How do I read a text file line by line?

Java, Tip 20.11.2013 No Comments

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();

Leave a Reply

s2Member®