【发布时间】:2012-02-11 18:49:43
【问题描述】:
我有以下代码从我的文件中检索数据。当我执行代码时,我知道它只给出了总行数的 50%。为什么会这样?
public static void main(String args[]) throws IOException
{
int count = 1;
try {
FileInputStream fileInput = new FileInputStream("C:/FaceProv.log");
DataInputStream dataInput = new DataInputStream(fileInput);
InputStreamReader inputStr = new InputStreamReader(dataInput);
BufferedReader bufRead = new BufferedReader(inputStr);
while(bufRead.readLine() != null)
{
System.out.println("Count "+count+" : "+bufRead.readLine());
count++;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
【问题讨论】:
-
修复将是字符串行; while ((line=bufRead.readLine()) != null), 删除第二个 readline。
标签: java file filestream