File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Help with some code for text read in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with some code for text read in java " Watch "Help with some code for text read in java " New topic
Author

Help with some code for text read in java

Jeff Heagle
Greenhorn

Joined: May 09, 2011
Posts: 3
Hi Everyone, I'm new to java and working on reading a text file into my java program. The issue with the code I have built is it only reads the text on each line and errors if there is more that one text on the line. Looking for some advice.

Here is the txt reader,


I need it to read 1 2 3 4 5, and let me choose one of them, right now I can only get it to read
1
2
3
4
5
from the text file. I believe it has something to do with my rates[i] = Double.parseDouble(line); but can't figure out how to correct it. Please help I'm not getting any help anywhere else.


Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
Use String.split(...) to split the line of data into an array. Then you need to parse each entry in the array.
Jeff Heagle
Greenhorn

Joined: May 09, 2011
Posts: 3
Could you show an example? I've been trying to figure it out all day. Am I on the right track here?
Jeff Heagle
Greenhorn

Joined: May 09, 2011
Posts: 3
Got it now.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38793
    
  23
Since Java5, most people would use a Scanner. Just beware of its nextLine method; it doesn't quite do what you think.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38793
    
  23
. . . and welcome to the Ranch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with some code for text read in java