原代码:
FileInputStream fis = new FileInputStream(source);
FileOutputStream fos = new FileOutputStream(target);
byte[] bts = new byte[300];
while (fis.read(bts, 0, 300) != -1) {
fos.write(bts, 0, 300);
}
fos.close();
fis.close();
更改后代码
FileInputStream fis = new FileInputStream(source);
FileOutputStream fos = new FileOutputStream(target);
byte[] bts = new byte[300];
int len=-1;
while ((len=fis.read(bts)) != -1) {
fos.write(bts, 0, len); //更改处
}
fos.close();
fis.close();

本文介绍了一种使用Java进行文件复制的方法,通过优化读写过程,确保了数据的完整性和高效性。

1130

被折叠的 条评论
为什么被折叠?



