Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Detecting EOF  RSS feed

 
Varek Boettcher
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm writing a csv text file parser. The parser is fine but determining when I've reached the end of the file has proved to be a pain.
Take the following code:

As I read each line from the file to parse, I use a while loop that goes something like:

The problem is if I use r.ready() (the FileReader) it goes false before all the lines are read. If I use br.ready() (the BufferedReader) it returns true even when the next br.readLine() returns null.
I need to know when I've ACTUALLY reached the end of the file. Can anyone suggest anything?
Thanx much in advance!
Varek
 
Rich Cohen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method BufferedReader.readLine is specified to return null at end-of-file. So just call readLine until it returns null.
 
Richard Rodger
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You also need to handle the special case where newlines are quoted.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!