Java read file with BufferedReader

 

In this example, we will see how to use one of the basic Java IO operations, which is reading a file with BufferedReader class.

The principle is to use a buffer whose size can be parametered, so instead of reading character by character, we read a larger block at a time.

The following code shows how to use BufferedReader to read a file and display its content in the console:

 

If we want to read by block of 3Kb, we will use the following statement :