public class ReadFileLineByLineUsingBufferedReader {
public static void main(String[] args) {
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader("sample.txt"));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
// This is where you would split your individual line
// read next line
line = reader.readLine();
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
1条答案
按热度按时间j8ag8udp1#
你试过逐行阅读这个文件吗?
下面是一个如何执行此操作的示例(https://www.digitalocean.com/community/tutorials/java-read-file-line-by-line):