• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading in a file

 
Takumi Fujiwara
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program is suppose to read in a file and use the StringTokenizer to turn the file into tokens. However, I get a compile error when I try to read the file in.



Also, I am having trouble with my StringTokenizer. I'm not exactly sure how it's suppose to turn things into tokens. I referred to Java Sun's site, but their tutorial left me with many questions. So far I've gotten:



I am unsure what the nextToken method should exactly do since it returns a string. Any help would be appreciated.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your reader looks about like mine. I have a little utility file reader because I can never remember this syntax. Here are two constructors:

What kind of compiler error do you get?

Re the Tokenizer, the code you showed will break a line into space-delimited words. So put it to work on one line at a time.

I'm not sure what you're supposed to do with the tokens ... maybe put them all in a big Vector or List or something.

That went a little further than we usually prefer toward giving you a working answer, but the examples here are very common bits of syntax ... hard to give out in much smaller bits. Hope it helps without taking away the fun (and value) of exploring things yourself!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!