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.