Hi ryan, Please use CodeTags while posting code. So what is it that you want to know from us? Is it that your program does not perform as expected? If the file you are parsing can be big, you may be better of using a StreamTokenizer.
Originally posted by ryan bohnert: The example above didn't print anything for words and words.
That's odd. It sure looks like it should work. Just be aware that StringTokenizer is deprecated:
StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.
Ryan, I suggested you to use java.io.StreamTokenizer and not StringTokenizer!
Joe, Is the use of StreamTokenizer also discouraged? I thought it will be a better choice because it will not load the entire string in memory at a time and run the split on the entire content which may be a bad idea if the file is huge.
Originally posted by Nitesh Kant: Is the use of StreamTokenizer also discouraged?
The API does not state that StreamTokenizer is discouraged, so I think your suggestion was fine.
Originally posted by Nitesh Kant:
I thought it will be a better choice. . .
Our friend was processing a line at a time, so I don't think that would be a problem (for reasonable line lengths, of course). He's using a BufferedReader which will buffer 8k of the file anyway. I'm curious as to why String.split() was not working. Unless his line starts with unprintable characters, it should have worked. [ February 29, 2008: Message edited by: Joe Ess ]