How to read a text file in Java - BufferedReader Example

There are multiple ways to read a file in Java e.g. you can use a Scanner as we have seen in the last example, or you can use the BufferedReader class. The advantage of using a BufferedReader to read a text file is speed. It allows faster reading because of internal buffering provided by BufferedReader. Other Reader classes e.g. FileReader access the file or disk everytime you call the read() method but BufferedReader keeps 8KB worth of data in its internal buffer which you can read it without accessing file multiple times. It's loaded when you access the file first time for a subsequent read. The BufferedReader class is also a good example of Decorator design pattern because it decorates existing readers e.g. FileReader to provide buffering, remember, the reading from file functionality still comes from the FileReader class.
Read more »