Skip to content
Related Articles
Open in App
Not now

Related Articles

Java FileReader Class ready() Method with Examples

Improve Article
Save Article
  • Last Updated : 11 Mar, 2022
Improve Article
Save Article

Java FileReader class is used to read data from the data file. It returns the data in byte format as FileInputStream class. This is a character-oriented class that is used for file handling in Java.

ready() Method of FileReader Class

It checks if the file reader is ready to be read. It will return a boolean that states if the reader is to be ready. It basically checks whether this stream is ready to be read or not. An InputStreamReader is ready if its input buffer is not empty as, or Thus, bytes are available to be read from the under byte stream of it.


public void ready()

Exception Thrown: IOException

Now we will be going through the sleep() method of thread class parallelly in order to have a good understanding of the ready() method of FielReader class. FOr that do remember certain important key points as follows:

Java FileReader Class is a class that is basically a file of execution of the programs to read data from the data file. It is present in FileInputStream class. contains the Java FileReader Class ready() method. The ready() method is used to check if the file reader is ready to be read. It will return a boolean that states if the reader is to be ready for it

  • Method Whenever FileReader Class ready() functions to execute, state if the reader is to be ready for it to read or not
  • If any other error or action interrupts when the file is, then IOException will be thrown.

Overrides: ready() in class Reader

Return Type: sleep() Method

It does not return any value, i.e., the return type of the sleep function is void. This method returns True if the next read() is Explaining not to block for input, or false otherwise. hence Note – that returning false does not guarantee that the next read will be blocked.

Exception Thrown: IOException is thrown if an I/O error has occurred.



// Java Program to Illustrate read() Method
// of FileReader Class
// Importing required classes
import java.util.*;
// Class
class GFG {
    // Main driver method
    public static void main(String[] args)
        // Try block to check for exceptions
        try {
            // Creating a Reader instance for it
            String strg = "Reading the Article";
            Reader readxyz = new StringReader(strg);
            // Checking if the Reader is Ready to read
            System.out.println("Is Reader ready Now "
                               + "to be read: "
                               + readxyz.ready());
            // Getting the character to read from stream
            int pqr;
            // Read the first 4 characters to this reader
            // using read() method
            // Setting up the str in the stream
            // for to read by the reader
            for (int i = 0; i < 4; i++) {
                pqr =;
                // Print statements
                System.out.println("\nInteger value "
                                   + "of character read: "
                                   + pqr);
                System.out.println("Actual "
                                   + "character read: "
                                   + (char)pqr);
            // Closing the connections
            // using close() method
        // Catch block to handle the exceptions
        catch (Exception e) {
            // Displaying exceptions on console



Is Reader ready Now to be read: true

Integer value of character read: 82
Actual character read: R

Integer value of character read: 101
Actual character read: e

Integer value of character read: 97
Actual character read: a

Integer value of character read: 100
Actual character read: d


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!