I have a strange problem where I have a log file called transactionHandler.log.It is a very big file having 17102 lines.This i obtain when i do the following in the linux machine:
wc -l transactionHandler.log
17102 transactionHandler.log
But when i run the following java code and print the number of lines i get 2040 as the 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);
}
}
Can you please tell me the reason.