• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read integers from a file

 
John Powell
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to read integers from a file (2 integer values separated by whitespace) that the program will use as variables. The following code works correctly. I was wondering, is there an easier method to read integer values from a file and then assign the values to specific variables?

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's pretty straightforward. If you're on JDK 1.4 or later, you can replace StringTokenizer with String.split() to tighten things up a bit. Test with some incorrect input, see what happens now and decide what you want to have happen:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic