Forums Register Login

Reading up to the first delimiter and then moving on to next line.

+Pie Number of slices to send: Send
I have a text file that has contents as follows:

testing1,true,0,0.0,0,0.0,4.0,0.0,0.0,0.0,0.0
test2,true,0,0.0,0,0.0,4.0,0.0,0.0,0.0,0.0

I am trying to read only the first item in each list using a comma as a delimiter using the following code.



At line 16, with nextLine, I get the following in a drop down menu:

testing1,true,0,0.0,0,0.0,4.0,0.0,0.0,0.0,0.0
test2,true,0,0.0,0,0.0,4.0,0.0,0.0,0.0,0.0

If I change line 16 to next(), i get the following example:

testing1
true
0
0.0
0
4.0 and so on

I've taken a look around, but not really finding the solution. I know I am probably missing something simple and I'm probably going to slap my forehead once the mistake is revealed, but what am I missing, doing wrong?

+Pie Number of slices to send: Send
I feel dumb!

Solution:



Solution was simply adding one line to advance to next line and fixing a small error in the while loop.

Thanks anyways for taking a look guys.
+Pie Number of slices to send: Send
Don't worry we've all had those Doh!! moments. And thanks for updating the thread with the solution.
Fire me boy! Cool, soothing, shameless self promotion:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 750 times.
Similar Threads
Using Swing to display an array from text file issues
Scanner help
Reading words from a file
Need help with Reading input from a text file into an arraylist
Scanning a text file
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 22:04:41.