Java Q: Reading input text

c_loke

n00b
Joined
Sep 27, 2006
Messages
31
Just a quick question. I have to write something that reads a text file containing ascii text. There are paragraphs in the input file which are separated by blank single lines.

If I use a fileReader and a BufferedReader, how does it handle reading the separated blank single lines?


From reading the java doc, it says for the readLine method (which is what im trying to use)in BufferedReader,

"Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. "

I think what it means is that readLine will terminate when it reads the separated blank single line. Can anyone confirm this?


The way I am approaching this is to read each line of the and then append the next line to the previous line until it reaches the end of the paragraph. However, I am unsure how readLine will handle the blank line so I am a bit hesitant to continue on.

Hopefully what I said was clear enough :p
 
readLine() will return an empty string ("") when it reads an empty line so you can detect that to determine when you're going to get a new paragraph
 
Ok great. And when readLine() reaches the end of the file, will it read null and return null?
 
Back
Top