File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Blank lines in file throwing exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Blank lines in file throwing exception" Watch "Blank lines in file throwing exception" New topic
Author

Blank lines in file throwing exception

Tony Fabeets
Ranch Hand

Joined: Dec 22, 2003
Posts: 38
Happy Holidays! The problem is the program works just fine until it hits a blank line. Then the jvm takes up 99% of my resources and the my gui locks on my screen. Sry for the long code, but figure it'll be easier to diagnose.
tried if(inputLine.equals("")continue; and if(inputLine.equals("")inputLine = reader.readLine(); no avail

[ December 28, 2003: Message edited by: Tony Fabeets ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

Originally posted by Tony Fabeets:


When you hit a blank line, you get an endless loop.


[How To Ask Questions On JavaRanch]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Good catch, Joe! This is common practice:

This takes advantage of the fact that in Java an assignment clause (line = something) is a function. That is, it not only assigns a value to a variable, but returns that value, too. So in one swell foop we can read a line, check it for null and terminate the loop. With this in place, your "continue" clause will skip the rest of the loop and read another line.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Tony Fabeets
Ranch Hand

Joined: Dec 22, 2003
Posts: 38
It's still blowing up on the empty line, no matter what i try... help please?

.equals("\r") fixed the prob
[ December 24, 2003: Message edited by: Tony Fabeets ]
[ December 24, 2003: Message edited by: Tony Fabeets ]
[ December 24, 2003: Message edited by: Tony Fabeets ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Blank lines in file throwing exception