// 经典读取数据三(大文件)
public static void readerFile3(String path) {
int length = 0x8FFFFFF; // 128 Mb
try {
MappedByteBuffer out = new RandomAccessFile(path, "r").getChannel()
.map(FileChannel.MapMode.READ_ONLY, 0, length);
String result = "";
for (int i = 0; i < 130; i++) {
if (out.get(i) == 10) {
result = "";
System.out.println("换行了。");
} else {
result += (char) out.get(i);
}
if (out.get(i) == 13) {
System.out.println(result + ":" + (result.trim().length()));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Java读取大文件,超越内存限制
最新推荐文章于 2022-12-01 12:49:04 发布