【发布时间】:2020-12-14 16:35:36
【问题描述】:
我有一个 100mb 的大文件可供读写。
String fromFile1 = "file1.zip"; // 100mb file
String toFile2 = "file2.crypt"; // empty
In a loop
1. String chunk1 = fromFile1.read("50kb"); // I read in every loop 50kb
2. toFile2.write(chunk1); // I write in every loop 50kb
循环结束后,所有内容从file1.zip转移到file2.crypt。
Here by this concept I can avoid reading the entire file into memory
如何在 java 中最有效地做到这一点?
【问题讨论】:
-
将 CipherOutputStream 与缓冲流结合使用 - 这样可以减少内存使用量。
-
为什么
chunk1是String?
标签: java performance java-stream java-io