Read from a file using a BufferedReader

For reading text from a file it’s better to use a Reader class instead of a InputStream class since Reader classes have the purpose of reading textual input.
In this example we use the BufferedReader class to read text from a file line by line using it’s readLine method.
It is possible to read the data the same way as with the BufferedInputStream using either a byte array or read one byte at a time, but if you’re going to read plain text this is easier and produce more readable code.

In the example we simply create a BufferedReader object and start reading from the file line by line until the readLine method returns null, which indicates the end of the file.

See this example if you want to compare with reading from a BufferedInputStream:

Read from file with BufferedInputStream

Search for more Java info on this site here:
Custom Search

Any thoughts or questions?