• 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

reading and seperating a text file

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
im reading lines from a text file just fine..
what i need to do is seperate the line like so:
text.txt:
---------
100 500 1000
200 450 2000
300 475 7503
-------------------------
when i read line 1 i get: "100 500 1000"
i've tried multiple things, but can't get it to split the file up:
var1 = 100
var2 = 500
var3 = 1000
can someone help me out with this.. or point me in the right direction?

thanks
--
EG
[ November 19, 2003: Message edited by: Eric Giblock ]
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the StringTokenizer class. You'll probably also need to look at the Integer class for the appropiate methods to parse the tokenized string into numeric values.
Good luck. When you get some code worked out, post some more questions.
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this case (in any case for that matter) the split method from the String class will make your life easier:

I have not tested this code and for your purposes (if you'd like to compile the code) you'll have to handle (or catch) the NumberFormatException if parseInt throws a temper.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic