This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes StreamTokenizer and EOL problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "StreamTokenizer and EOL problem" Watch "StreamTokenizer and EOL problem" New topic

StreamTokenizer and EOL problem

Larry Frissell
Ranch Hand

Joined: May 16, 2008
Posts: 82
I am having a problem with this code. When I run it , can get the numbers fine, but I am not reading the StreamTokenizer.TT_EOL so I am stuck in the while loop forever.

My txt file looks like this:

Any ideas would be appreciated.
Thomas Thevis
Ranch Hand

Joined: Sep 02, 2008
Posts: 87
Actually, I don't know what's going wrong, but I would use the BufferedReader.readLine() method tor read the file line by line and parse each single line with the Scanner class.


SCJP 5.0, SCJD in progress
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 378
There are two while loops checking for TT_EOF
Could it be due to the outer while construct?
Larry Frissell
Ranch Hand

Joined: May 16, 2008
Posts: 82
I have worked around the problem, but I really do not understand the problem I was having with TT_EOL. For the program I am making, it was important to know when I reached the end of the line on the text file. By printing each of the inttoken.ttype I determined that at the end of each line I got an integer constant (-3) which is the constant for TT_WORD.

So I changed my inner while loop to

and I am no longer stuck in the loop.
I agree. Here's the link:
subject: StreamTokenizer and EOL problem
It's not a secret anymore!