BufferedReader跳过第一行 [英] BufferedReader to skip first line

查看:344
本文介绍了BufferedReader跳过第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下 bufferedreader 来读取文件的行,

I am using the following bufferedreader to read the lines of a file,

BufferedReader reader = new BufferedReader(new FileReader(somepath));
while ((line1 = reader.readLine()) != null) 
{
    //some code
}

现在,我想跳过阅读文件的第一行,我不想使用计数行 int lineno 保持行数。

Now, I want to skip reading the first line of the file and I don't want to use a counter line int lineno to keep a count of the lines.

如何做到这一点?

推荐答案

你可以试试这个

 BufferedReader reader = new BufferedReader(new FileReader(somepath));
 reader.readLine(); // this will read the first line
 String line1=null;
 while ((line1 = reader.readLine()) != null){ //loop will run from 2nd line
        //some code
 }

这篇关于BufferedReader跳过第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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