This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Scanner.nextLine() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Scanner.nextLine()" Watch "Scanner.nextLine()" New topic


gianni drughi

Joined: Jun 23, 2010
Posts: 8
hi all,
i'm going crazy with Scanner.nextLine() method! X|

i'm importing some data from a text file, i'm parsing them with a Scanner class.

that's in my txt file:


i correctly set reference to my file (i can see it with eclipse debugger).

the problem come out in this fragment of code:

when i execute for the first time the cycle, scanner.nextLine() return to me ".2" value
so it doesn't return to me the first row of my text file, but i need to get my rows in order for the correct working of my program

do you know what is happening?

thank you


marc weber

Joined: Aug 31, 2004
Posts: 11343

Welcome to the Ranch!

Your code fragment should work, as verified below. I suspect there might be something happening before your fragment to advance the scanner to the next line -- or there's something else happening in the method processContrattiLine (perhaps it's calling nextLine again?).

If TestData.txt contains...

...then the following code...

...produces this output...

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
It is sorta covered in the JavaRanch Style Guide.
subject: Scanner.nextLine()
Similar Threads
how to split a text file
Adding a new array element is not saving to memory
Another Scanner question
Question: Scanner and nextLine
Weird multiple output issue with if statements