Java IO Tutorial - Java Reader.ready()








Syntax

Reader.ready() has the following syntax.

public boolean ready()  throws IOException

Example

In the following code shows how to use Reader.ready() method.

/*w  w w  .j  av a  2  s  .c  om*/
import java.io.*;

public class Main {

   public static void main(String[] args) {

      String s = "tutorial from java2s.com";

      Reader reader = new StringReader(s);

      try {
         // check if reader is ready
         System.out.println(reader.ready());

         // read the first five chars
         for (int i = 0; i < 5; i++) {
            char c = (char) reader.read();
            System.out.println(c);
         }
         reader.close();
      } catch (IOException ex) {
         ex.printStackTrace();
      }
   }
}

The code above generates the following result.