public static void copy(File src,File dest) throws Exception{
FileInputStream fis=new FileInputStream(src);
FileOutputStream fos=new FileOutputStream(dest);
byte [] buffer=new byte[1024];
int hasRead=0;
while((hasRead=fis.read(buffer))!=-1){
fos.write(buffer, 0, hasRead);
fos.flush();
fos.close();
}
}
public static void main(String[] args) throws Exception {
copy(new File("c:\\1.txt"), new File("d:\\2.txt"));
}
看完程序思考这么几个问题
1如果我们想加快文件的拷贝速度可以考虑什么
2当我们考一个文件的时候如果接着再去拷贝一次,肯定会变慢,为什么?
但是当我们等上这么一段时间之后再去拷贝速度又会变快,这是为什么?