permaculture playing cards
The moose likes Java in General and the fly likes StreamTokenizer usage 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 » Java in General
Bookmark "StreamTokenizer usage" Watch "StreamTokenizer usage" New topic

StreamTokenizer usage

Sandeep Lakshmipathy
Ranch Hand

Joined: Mar 05, 2002
Posts: 31
Dear Friends,
I want some help on using the StreamTokenizer. I have to read comma separated data from a file and retrieve the each value for processing. I thought of using the treamTokenizer where I can directly give a Reader as input and start getting the tokens. But I notice that I have no option to specify comma as a delimiter, something that can be done in the String tokenizer, and the nextToken() returns int values.
How do I handle these int values to be interpreted as some numbers directly? Also, using a StringTokenizer will not be efficient since I will have to form a new StringTokenizer object for each line that is read (Or is there a way out for this issue? Please let me know).

Sandeep Lakshmipathy
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
the problem with StringTokenizer in such a case is that if one of the fields has no value, ie not even a space between the commas, then you dont get a token for it, so things could get messy.
you could use a BufferedReader and read a line at a time, then use indexOf(",") or indexOf(",", int fromIndex) and/or substring()
I agree. Here's the link:
subject: StreamTokenizer usage
jQuery in Action, 3rd edition