import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
public class FileSaveAs {
File f;
byte[] bit=new byte[100];
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method
FileSaveAs filesa=new FileSaveAs();
filesa.Open("f:\\123.txt");
filesa.SaveAS("f:\\12.txt");
}
public void Open(String filename){
f=new File(filename);
if(f.exists()){
try{
String temp;
FileReader fr=new FileReader(f);
BufferedReader br=new BufferedReader(fr);
while((temp=br.readLine())!=null){System.out.println(temp);}
fr.close();
br.close();
}catch(IOException e){
}
}
}
public void SaveAS(String filename) throws IOException{
File t=new File(filename);
FileOutputStream fot=new FileOutputStream(t);
FileInputStream fit=new FileInputStream(f);
fit.read(bit);//以字節形式讀取
fot.write(bit);//以字節形式寫入文件
fit.close();
fot.close();
/*String temp; ///字符串形式寫入文件
t.createNewFile();
BufferedReader br=new BufferedReader(new FileReader(f));
FileWriter fw=new FileWriter(t);
while((temp=br.readLine())!=null){
fw.write(temp);
}
br.close();
fw.close();*/
}
}