Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StreamTokenizer Problem - EOL getting confused with EOF

Status
Not open for further replies.

cRODEEkrank

Technical User
Dec 5, 2001
41
0
0
US
Hello,

I'm writing a program that is reading text file contents from a client into a server program. The text file has student grades listed on a separate line. I'm using a LineNumberReader()in the client program to read the line, then am writing the line to the server.

I'm using a StreamTokenizer to read in the line and parse the string into words and numbers. The problem is, it's only reading in one line from the file instead of the 13 it should be.

Here's an example of my Server-side code:

StreamTokenizer sT = new StreamTokenizer(new BufferedReader(new InputStreamReader(s.getInputStream()))); sT.eolIsSignificant(true);
while (endOfFile == false)
{
tokValue = sT.nextToken();
switch(sT.ttype)
{
case StreamTokenizer.TT_EOL: System.out.println("End of line.");
break;

case StreamTokenizer.TT_NUMBER:
System.out.println(sT.nval);
break;

case StreamTokenizer.TT_WORD:
System.out.println(sT.sval);
break;

case StreamTokenizer.TT_EOF:
endOfFile = true;
break;

default:
System.out.println("hi");
}
}

When it reads the last number off the first line, it gets
passed a -1 which the program is interpreting as EOF but it's actually the EOL. Can anyone help with this?

Thanks!
Crod
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top