File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Skipping a blank line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Skipping a blank line" Watch "Skipping a blank line" New topic

Skipping a blank line

Darrell Morello
Ranch Hand

Joined: Apr 28, 2005
Posts: 38
How do I make sure that empty lines are skipped when reading a file. I mean if the user has hit the return key twice after a line, and then started the next line, how do I make sure that the empty line is not read? I also want to ignore any line that has anything other than a letter. So numbers also off.

For example, the file can be

Heres my code so far


[ May 25, 2005: Message edited by: Darrell Morello
[ May 26, 2005: Message edited by: Darrell Morello ]
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
As you process the inputStream, between your while(line != null){ and your line = inputStream.readLine(), you should just jump over any lines that you don't need, according to thejavadocs, it says:

public String readLine()
throws IOExceptionRead 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.

A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
IOException - If an I/O error occurs

So what happens when you read a blank line? You would get a String with length 0. So, just don't process lines of length 0, or if they start with anything other than a letter.
Fahd Shariff
Ranch Hand

Joined: Nov 22, 2002
Posts: 38
To check for digits:

Fahd Shariff<br />"Let the code do the talking"
Darrell Morello
Ranch Hand

Joined: Apr 28, 2005
Posts: 38
Alright, thanks
I agree. Here's the link:
subject: Skipping a blank line
jQuery in Action, 3rd edition