Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jenn Terry
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Jenn Terry
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tony Docherty
Bartender
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't worry we've all had those Doh!! moments. And thanks for updating the thread with the solution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic