-4

可能重复:
仅从输入中读取某些行?

如果我使用 BufferedReader,有没有办法可以跳过文件中的每一行?

4

2 回答 2

1

只需阅读一行并丢弃它:

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
}
于 2012-04-21T15:34:12.147 回答
0

BufferedReader br = ...;
String line;
while ((line = br.readLine()) != null) {
    line = br.readLine();
    //do whatever with the data
    if (line == null) break;
}
于 2012-04-21T15:33:12.117 回答