我有一个奇怪的问题,我有一个名为transactionHandler.log的日志文件.它是一个非常大的文件,有17102行.这是我在linux机器上执行以下操作时获得的:
wc -l transactionHandler.log
17102 transactionHandler.log
Run Code Online (Sandbox Code Playgroud)
但是,当我运行以下java代码并打印行数时,我得到2040作为o/p.
import java.io.*;
import java.util.Scanner;
import java.util.Vector;
public class Reader {
public static void main(String[] args) throws IOException {
int counter = 0;
String line = null;
// Location of file to read
File file = new File("transactionHandler.log");
try {
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
line = scanner.nextLine();
System.out.println(line);
counter++;
}
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println(counter);
}
}
Run Code Online (Sandbox Code Playgroud)
你能告诉我原因吗?