Read Text File in Java using BufferedReader

Sharing is Caring

Previously I have posted about reading text file using FileInputStream and this post shows how to read text file in java using BufferedReader class.

This is a sample text file

Sample Text File - BufferedReader

and this is the java code to read text file using BufferedReader class

package client;


public class ReadFileBfr {
    public ReadFileBfr() {

    public static void main(String[] args)  {
        // Absolute path of file that you want to read
        File f = new File("D:/sampleFile.txt");

        BufferedReader bfr=null;
        try {
            bfr = new BufferedReader(new FileReader(f));
        } catch (FileNotFoundException e) {

        String data;
        //Iterate over file content
        try {
            while ((data = bfr.readLine()) != null)
        } catch (IOException e) {


Execute this java code

Output is

Read text file in java using BufferedReader

Cheers 🙂 Happy Learning

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *