cRODEEkrank
Technical User
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
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