BufferedReader readLine returning NoSuchElementException
I'm using BufferedReader and readLine to read a textfile into a program.
The lines are terminated by CRLF strings.
The problem is that there are some empty lines, that is, there are
sequences of CRLFCRLF without any interverning characters. The readLine
throws a NoSuchElementException, and never reaches the end of the file.
How can I get readLine to read the whole file and terminate at the end?
Here is some test code:
try {
int i = 0;
File f = new File(args[i]);
System.out.println("Begin Processing " + f.toString() + " ..." +
f.toURL() + " ...");
br = new BufferedReader(new FileReader(f));
System.out.println("Now Processing " + " ...");
try {
while ((line=br.readLine())!=null) { // lines are terminated by CRLF
System.out.println("Line " + " ..." + line);
processSCALine(line);
} // while
}
catch (Exception e) {
System.out.println("Exception reading: " + e.toString() + " Line " +
" ..." + line);
}
finally {
br.close();
}
}
catch (Exception e) {
System.out.println("Exception opening: " + e.toString());
return;
}
}
--
In memorium Layal Najib
www.cpj.org