• Post Reply Bookmark Topic Watch Topic
  • New Topic

reading and seperating a text file  RSS feed

 
Eric Giblock
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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 ]
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • 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.
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!