Hi, I want to know is there any efficient way to find out the number of records in the variable length text file. I have tried 2 ways using BufferedReader & LineNumberReader but I am getting a same performance.To count 50,000 records both APIs taking 12 seconds.But is there any other way to calculate the above functionality. Code ex ------- System.out.println(new Date()); LineNumberReader in = new LineNumberReader(new FileReader("test.txt")); while(in.readLine() != null); System.out.println(in.getLineNumber()); System.out.println(new Date()); in.close(); System.out.println(new Date()); BufferedReader bf = new BufferedReader( new FileReader("test.txt")); int count = 0; while(bf.readLine() != null) count++; System.out.println(count); System.out.println(new Date()); Thanks Saran.
The key here is to first of all use a lower level InputStream and then let parallel processing do the work for you:
I got a record count of 50034 on my test.txt (which I manufactured from some long system log files) in about 2 seconds on a P2-400 (a real slowpoke). So you should be able to cut this down to about a second. Hope this helps.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher