Read Text File in Java using FileReader Class

Sharing is Caring

Previously I have posted about reading text file using FileInputStreamBufferedReader and Scanner Class. This post shows how to read text file in java using FileReader class.

This is a sample text file

Sample Text File - FileReader Class

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

package client;


public class ReadFileFr {
    public ReadFileFr() {

    public static void main(String[] args) {
        // Absolute path of file that you want to read
        FileReader fr=null;
        try {
            fr = new FileReader("D:/sampleFile.txt");
        } catch (FileNotFoundException e) {

        int data;
        //Iterate over file content
        try {
            while ((data = != -1)
                System.out.print((char) data);
        } catch (IOException e) {


Execute this java code

Output is

Read text file in java using FileReader

Cheers 🙂 Happy Learning

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

Leave a Reply

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