Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StreamTokenizer usage

 
Sandeep Lakshmipathy
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic