gpt4 book ai didi

java - 使用缓冲读取器读取随机访问文件

转载 作者:行者123 更新时间:2023-12-02 07:40:33 26 4
gpt4 key购买 nike

我正在尝试读取一个大文件(> 1GB),我认为使用缓冲读取器将其作为随机访问文件读取会很有效。

我需要逐行读取文件并解析它

然而,作为 JAVA IO Api 的新手,我不确定如何做到这一点..

感谢您的帮助。

最佳答案

您可以使用 Java 的 BufferedReader 来实现此目的:

BufferedReader reader = new BufferedReader(new FileReader(fileName));
String line;
while ((line = reader.readLine()) != null) {
// Do some stuff with the line
}

fileName 是您要读取的文件的路径。

关于java - 使用缓冲读取器读取随机访问文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11672523/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com