• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Scanner.nextLine()

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

FISSO=0
.2
.2
.2
.2

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

--

faciolo
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
reply
    Bookmark Topic Watch Topic
  • New Topic