aspose file tools*
The moose likes Beginning Java and the fly likes How to read a word without bothering if it is a word or number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to read a word without bothering if it is a word or number" Watch "How to read a word without bothering if it is a word or number" New topic
Author

How to read a word without bothering if it is a word or number

Roy Sin
Greenhorn

Joined: Sep 27, 2001
Posts: 2
hi
i have this problem... i am using the StreamTokenizer to read one word at a time... however, when i read words like 3G.. the StreamTokenizer will break up the 3 and G and read them seperately.. how do i solve this prob ? the code is as follows :
while (innerReader.ttype != StreamTokenizer.TT_EOF)
{
if (innerReader.ttype == StreamTokenizer.TT_WORD)
{
record = innerReader.sval;
record = record.toLowerCase();
}
else if (innerReader.ttype == StreamTokenizer.TT_NUMBER)
{
record=innerReader.nval;
}
System.out.println(record);
innerReader.nextToken();
}
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Hi Roy -
I haven't used the StreamTokenizer before, but the docs do say it reads a byte at a time; therein lies your problem.
To get the behavior you want, you'll probably have to read in a line at a time, and use the java.io.StringTokenizer class to parse it.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to read a word without bothering if it is a word or number