• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Record count

 
saran sankar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
saran sankar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much michal.
Saran.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic