且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java:InputStream 读取大文件太慢

更新时间:2023-01-09 17:20:17

I ran this code with a 183 MB file. It printed "Elapsed 250 ms".

final InputStream in = new BufferedInputStream(new FileInputStream("file.txt"));
final long start = System.currentTimeMillis();
int cnt = 0;
final byte[] buf = new byte[1000];
while (in.read(buf) != -1) cnt++;
in.close();
System.out.println("Elapsed " + (System.currentTimeMillis() - start) + " ms");