• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

StreamTokenizer

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm using StreamTokenizer to read contents from a text file. I want to retain the spaces in the text file, but streamtokenizer removes the spaces and appends all the characters in the file. I tried using ordinaryChar() method, but that didn't really help either. Any suggestions would really help...

Reader read = new BufferedReader(new InputStreamReader(myFile));//read the contents using buffered reader
StreamTokenizer in = new StreamTokenizer(read); //read the tokens
in.ordinaryChar(' ');


Thanks.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think StreamTokenizer returns the delimiters (i.e. the spaces) to you. Why do you need them anyways? If you can explain your reasoning here, we might be able to help you find an alternate solution. Perhaps StringTokenizer will help, but I'm unsure that this is what you really need.

Layne
 
Rancher
Posts: 3389
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StreamTokenizer can be tailored:

stzr.ordinaryChar(' '); // Return spaces

will return the space character which you handle as below in the switch stmt:
case ' ':
 
vinodh venkataraman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My program has to choose random sentences based on a randomly generated line number from a text file. I thought using StreamTokenizer will help me use the lineno() function for selecting a random line number.
Anyways, I'm gonna try the case ' ' option and see how it works...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!