Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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);
}
 
PREVIOUS NEXT
Tagged: #java #read #line #file
ADD COMMENT
Topic
Name
3+3 =