如果我使用BufferedReader,有没有办法可以跳过文件中的每一个奇数行?
答案 0 :(得分: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
}
答案 1 :(得分:0)
BufferedReader br = ...;
String line;
while ((line = br.readLine()) != null) {
line = br.readLine();
//do whatever with the data
if (line == null) break;
}