📜  java读取文件的第一行 - Java代码示例

📅  最后修改于: 2022-03-11 14:52:28.110000             🧑  作者: Mango

代码示例1
// this is called "try-with-resources" statement in java 8.
// it ensures that the resources are closed at the end.
  
try (BufferedReader br = new BufferedReader(new FileReader(textFile))) {
    String text = br.readLine(); // first line only
    System.out.println(text);
}