Java NIO FileChannel复制导致文件大而不是BufferedReader和PrintWriter

时间:2018-07-12 16:50:51

标签: java nio fileinputstream fileoutputstream filechannel

我正在编写代码,将一个文件的内容复制到另一个文件。

旧代码: FileChannel source = new FileInputStream(inputFile).getChannel(); FileChannel destination = new FileOutputStream(outputFile).getChannel(); destination.transferFrom(source, 0, source.size());

此代码使我的程序冻结大约一分钟,以复制〜5MB的文件。仅使用常规的BufferedReader和PrintWriter即可正常工作。

此问题的解释是什么?是因为它试图在复制之前先将所有内容读取到内存中吗?

0 个答案:

没有答案