Forums Register Login

Help with some code for text read in java

+Pie Number of slices to send: Send
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.


+Pie Number of slices to send: Send
Use String.split(...) to split the line of data into an array. Then you need to parse each entry in the array.
+Pie Number of slices to send: Send
Could you show an example? I've been trying to figure it out all day. Am I on the right track here?
+Pie Number of slices to send: Send
Got it now.
+Pie Number of slices to send: Send
Since Java5, most people would use a Scanner. Just beware of its nextLine method; it doesn't quite do what you think.
+Pie Number of slices to send: Send
. . . and welcome to the Ranch
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 905 times.
Similar Threads
NullPointerException
FileReader / BufferedReader will only read the first line from the file
parse a csv file (PLEASE HELP)
Problem reading a file
cannot instantiate the the type Flower
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:39:47.