可能重复:
仅从输入中读取某些行?
如果我使用 BufferedReader,有没有办法可以跳过文件中的每一行?
只需阅读一行并丢弃它:
BufferedReader bReader = new BufferedReader(new FileReader("someFileName.txt"));
String line = null;
while(true)
{
//skip the odd line
bReader.readLine();
//read an even line
line = bReader.readLine();
if(line != null)
//do stuff with even line
else
break; //end of input
}
BufferedReader br = ...;
String line;
while ((line = br.readLine()) != null) {
line = br.readLine();
//do whatever with the data
if (line == null) break;
}