//這是你的源文件,本身是存在的
File beforefile = new File("c://a.txt");
//這是你要保存之后的文件,是自定義的,本身不存在
File afterfile = new File("d://a.txt");
//定義文件輸入流,用來讀取beforefile文件
InputStream in = new FileInputStream(beforefile);
//定義文件輸出流,用來把信息寫入afterfile文件中
OutputStream out = new FileOutputStream(afterfile);
//文件緩存區
byte[] bytes= new byte[1024];
//將文件流信息讀取文件緩存區,如果讀取結果不為-1就代表文件沒有讀取完畢,反之已經讀取完畢
while(in.read( bytes )!=-1){
//將緩存區中的內容寫到afterfile文件中
out.write( bytes );
out.flush();
out.close();
}
}