How to read a text file line by line in java?

One of the java.io.reader implementations named BufferedReader gives efficient API to read character input line by line. As you can assume from the name of the class itself that it create an in memory cache or buffer of the given file and load/re-load the buffer on demand. If you are working with a large file and have enough primary memory, then you may use large buffer size for better performance. One of the constructors of BufferedReader takes the size of the buffer as an argument.

Code Snippet to create Buffered Reader.

Complete Sample Code.