• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Reading in a file

 
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.
 
(instanceof Sidekick)
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!
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic