|
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();
One Ping to “How do I read a text file line by line?”
One Response to “How do I read a text file line by line?”
-
John Bright Says:
May 24th, 2011 at 9:17 pmHey i just visited your site for the first time and i really liked it, i bookmarked it and will be back



December 9th, 2009 at 8:49 am
[...] 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 [...]