Forums Register Login

StreamTokenizer usage

+Pie Number of slices to send: Send
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).
Thanks
+Pie Number of slices to send: Send
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()
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 798 times.
Similar Threads
Upload File Servlet Example
creating and parsing csv files
CSV file help
StreamTokenizer and String Tokenizer
Converting String to an array.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:28:44.