Real world read from file Java

If there is an input file with tons of records, each record with be one line, each record is consisted of one id number, time the record is created and record content. Then what will be the best way to read and parse the file?

For example, the input is:

123-456-789   1:23pm Jan 4, 2014   I AM THE CONTENT!  
987-654-321   3:21pm Apr1, 2014    I AM THE CONTENT TOO!   

To read one line each time, I believe there is no much difference between scanner and bufferedReader because scanner also has 1k buffer. So may I do:

Scanner scan = new Scanner(new File("filename"))?

Then after I get one line, should I make another scanner object to parse the line and get each field (I can give the line as the input for the scanner)? Or is there any other better solution?

For experienced programmer, what should be the best way (fast, better performance) to do read and parse such a file with tons of records in real world? Thank you!


Unless 'tons' means hundreds of millions of lines it isn't likely to make any significant difference which you use, but you only need one Scanner object for this task, not one per line.

NB BufferedReader has a 4k buffer, so your only stated reason for thinking there is 'not much difference' is out the window. The fact that Scanner is a higher-level API with tokenising features also seems to have escaped you.

Need Your Help

Sphinx php api not working

php sphinx

I've been trying to use sphinx through PHP, and so far I've had absolutely no luck whatsoever.

How to run certain task every day at a particular time using ScheduledExecutorService?

java timertask background-thread scheduledexecutorservice

I am trying to run a certain task everyday at 5 AM in the morning. So I decided to use ScheduledExecutorService for this but so far I have seen examples which shows how to run task every few minute...