Answers for "java read first line of file"

0

java read first line of file

// 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);
}
Posted by: Guest on September-15-2021

Code answers related to "java read first line of file"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language