• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Blank lines in file throwing exception

 
Tony Fabeets
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9313
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tony Fabeets:


When you hit a blank line, you get an endless loop.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tony Fabeets
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic