java read first line of file

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

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
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}