File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Reading up to the first delimiter and then moving on to next line. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading up to the first delimiter and then moving on to next line." Watch "Reading up to the first delimiter and then moving on to next line." New topic
Author

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

Jenn Terry
Ranch Hand

Joined: Feb 22, 2014
Posts: 46
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

Joined: Feb 22, 2014
Posts: 46
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

Joined: Aug 07, 2007
Posts: 2232
    
  47
Don't worry we've all had those Doh!! moments. And thanks for updating the thread with the solution.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading up to the first delimiter and then moving on to next line.