Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

file io - Java - Scanner Class - Skipping over the first line when reading a textfile

When using a Scanner object to read from a textfile, I want it to skip over the very first line in the file. How would I do achieve this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just use file.nextLine() before your while loop. This will skip the first line, as explained in the JavaDoc.

And a note about your naming. The Java language has widely accepted conventions. Class Names always start with an upper case letter, and variable names always start with a lower case letter (except constants, but don't worry about that now). Read more here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...