• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to read data from a file...

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am at a lost as to where to begin...
I need to read data from a file (Example: 2c 4h 5d 9s)
then according to what letter is next to the number, I place in the proper
array spot. (So I am guessing multi-dimensional array?)
Umm... data is 13 'couplets' and I am at a total loss of where to begin. Do I need to use a string tokenizer, get one couplet, and then how do I tell from the couplet what letter it is.... I keep thinking this has to be simple, and I am just thinking too complex. I'm just not sure how to read mixed data types from a file (int/char pairs), and then how to figure out specifically what letter is from each pair. ANYWAY... ANY help at all on this problem would be MOST appreciated!!!
Jon
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try the following:
create a BufferedReader that is connected to a FileReader that is created using your file.
using readLine() you can read the lines of the file one at a time into a String
then tokenize the String you just read into smaller strings.
Then you could use the charAt() method of the String class to get each character.
Hope this helps
 
Jonathan King
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, thanks for the tip! Does this look like proper code for a situation for this?

or is this not legal usage of charAt? Can I parse it like that?
Any answers will be appreciated!!
Jon
 
reply
    Bookmark Topic Watch Topic
  • New Topic