As far I know, the two most common methods of reading character-based data from a file in Java is using Scanner or BufferedReader. I also know that the BufferedReader reads files efficiently by using a buffer to avoid physical disk operations.
My questions are:
- Does
Scannerperform as well asBufferedReader? - Why would you choose
ScanneroverBufferedReaderor vice versa?
Scanneris used for parsing tokens from the contents of the stream whileBufferedReaderjust reads the stream and does not do any special parsing.In fact you can pass a
BufferedReaderto ascanneras the source of characters to parse.