【发布时间】:2016-01-03 15:09:27
【问题描述】:
是否有可能使执行时间更快?
import java.io.*;
public class CopyFile {
public static void main(String[] args) throws Exception {
final long start = System.nanoTime();
InputStream in = new FileInputStream("test.pdf");
OutputStream out = new FileOutputStream("test_copy.pdf");
int c;
while ( (c = in.read()) != -1 )
out.write(c);
in.close();
out.close();
System.out.println("Took " + (System.nanoTime() - start) / 1000_000 + "ms to finish");
}
}
【问题讨论】:
-
是的。谷歌一下,你会找到的。顺便说一句,这段代码可以使用
Files.copy缩减为一行 -
当今人们无法从世界上最大的搜索引擎中找到任何东西,这是怎么回事。毕竟,谷歌搜索比编程容易得多。
标签: java performance io