java read first line of file

Solutions on MaxInterview for java read first line of file by the best coders in the world

showing results for - "java read first line of file"
Lilwenn
13 Jan 2020
1// this is called "try-with-resources" statement in java 8.
2// it ensures that the resources are closed at the end.
3  
4try (BufferedReader br = new BufferedReader(new FileReader(textFile))) {
5    String text = br.readLine(); // first line only
6    System.out.println(text);
7}