Java.io.CharArrayReader.ready() Method

Advertisements


Description

The java.io.CharArrayReader.ready() method validates if the stream is ready to be read. Character Array Readers are always ready to be read.

Declaration

Following is the declaration for java.io.CharArrayReader.ready() method:

public boolean ready()

Parameters

  • NA

Return Value

Returns true, if the next read is guraneeted not to block for input.

Exception

  • IOException -- If any I/O error occurs.

Example

The following example shows the usage of java.io.CharArrayReader.ready() method.

package com.tutorialspoint;

import java.io.CharArrayReader;
import java.io.IOException;

public class CharArrayReadDemo {
   public static void main(String[] args) {

      CharArrayReader car = null;
      char[] ch = {'A', 'B', 'C', 'D', 'E'};
      try{
         
         // create new character array reader
         car = new CharArrayReader(ch);
         
         // test whether the stream is ready to be read
         boolean isReady = car.ready();
         
         // print
         System.out.println("Ready ? "+isReady);
         
      }catch(IOException e){
         
         // if I/O error occurs
         e.printStackTrace();
      }finally{
         
         // releases any system resources associated with the stream
         if(car!=null)
            car.close();
      }
   }
}

Let us compile and run the above program, this will produce the following result:

Ready ? true



Advertisements
Advertisements