我建议您尝试使用内存映射。
FileChannel fc = new FileInputStream(file).getChannel();MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, (int) fc.size());
这将使整个文件几乎立即可用(大约10毫秒),并且几乎没有堆使用。BTW文件必须小于2 GB。

我建议您尝试使用内存映射。
FileChannel fc = new FileInputStream(file).getChannel();MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, (int) fc.size());
这将使整个文件几乎立即可用(大约10毫秒),并且几乎没有堆使用。BTW文件必须小于2 GB。