Java InputStreamReader.ready()

Syntax

InputStreamReader.ready() has the following syntax.

public boolean ready()  throws IOException

Example

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


/*w  w w .j a  v  a2  s. co m*/

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws IOException {

    int i;

    FileInputStream fis = new FileInputStream("C:/test.txt");
    InputStreamReader isr = new InputStreamReader(fis);

    while ((i = isr.read()) != -1) {
      char c = (char) i;
      System.out.println("Character read: " + c);
      // true if the next read is guaranteed
      boolean  bool = isr.ready();

      System.out.println("Ready to read: " + bool);
    }
  }
}