话不多说直接上代码:
import java.io.*;
public class BufferBackups {
public static void main(String[] args) throws IOException {
try{
File file1 = new File("D:/m.txt"); //源文件路径
File file2 = new File("D:/n.txt"); //复制后的文件路径
FileInputStream fis = new FileInputStream(file1);
FileOutputStream fos = new FileOutputStream(file2);
BufferedInputStream bufferedin = new BufferedInputStream(fis);
BufferedOutputStream bufferedout = new BufferedOutputStream(fos);
int temp = 0;
while((temp=bufferedin.read()) != -1) {
bufferedout.write(temp);
}
bufferedout.close();
}
catch (IOException e) {
System.out.println("系统中找不到该路径!");
}
finally {
System.out.println("本次复制完成!");
}
}
}