wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Read integers from a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Read integers from a file" Watch "Read integers from a file" New topic
Author

Read integers from a file

John Powell
Greenhorn

Joined: Nov 13, 2004
Posts: 11
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

Joined: Jan 29, 2003
Posts: 8791
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:


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read integers from a file
 
Similar Threads
Extract all integers from a text file, how to do?
Doubt about StringTokenizer !!
Threads
Array question
Threads/Arrays