Sep 09

The readLine() method of java.io.BufferedReader class reads the next line from a text file. When it reaches the end of the file it will return null.


BufferedReader in = new BufferedReader(new FileReader(filename));
String line = null;
while (null!=(line=in.readLine()))
{
   // process each line of file her
   // 'line' variable contains next line in file
}
in.close();

written by objects \\ tags: , ,

One Ping to “How do I read a text file line by line?”

  1. Using Scanner to read words from text file | web development helpdesk Says:

    [...] you need to read a file line by line. Alternatively sometimes you want to read text word by word (for example to count the occurrence of [...]


One Response to “How do I read a text file line by line?”

  1. John Bright Says:

    Hey i just visited your site for the first time and i really liked it, i bookmarked it and will be back :D

Leave a Reply