Java - 扫描器类 - 读取文本文件时跳过第一行 [英] Java - Scanner Class - Skipping over the first line when reading a textfile

查看:361
本文介绍了Java - 扫描器类 - 读取文本文件时跳过第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Scanner对象从文本文件读取时,我希望它跳过文件的第一行。我将如何做到这一点?

解决方案

这将跳过第一行,如



还有一个关于你的命名的注释。 Java语言已被广泛接受。类名始终以大写字母开头,变量名通常以小写字母开头(常数除外,但现在不用担心)。阅读更多此处


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?

解决方案

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.

这篇关于Java - 扫描器类 - 读取文本文件时跳过第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆