try {
BufferedInputStream in = new BufferedInputStream(
new FileInputStream(srcPath), STREAM_SIZE);
ByteArrayOutputStream out = new ByteArrayOutputStream(
STREAM_SIZE);
OutputStream oos = new FileOutputStream(destPath);
System.out.println(srcPath);
int size = 0;
byte[] temp = new byte[STREAM_SIZE];
while ((size = in.read(temp)) != -1) {
out.write(temp, 0, size);
// 缓冲输出流的缓冲区大于10M时写入输出流然后清空缓冲区
if (out.size() > STREAM_SIZE * 10) {
// 缓冲流中的数据写入输出流
out.writeTo(oos);
// 清空缓冲输出流
out.reset();
}
}
out.writeTo(oos);
in.close();
} catch (IOException e) {
System.out.println(e.toString());
}
Java快速从一个文件夹复制到另外一个文件夹
最新推荐文章于 2022-09-09 12:07:18 发布