PushbackReader ready() method in Java with Examples
The ready() method of PushbackReader Class in Java is used to check whether this PushbackReader is ready to be read or not. It returns a boolean which states if the reader is ready.
Syntax:
public void ready()
Parameters: This method does not accepts any parameters
Return Value: This method returns a boolean value which tells if this PushbackReader is ready to be read or not. It return true if it is ready. Else it returns false.
Exception: This method throws IOException if some error occurs while input-output.
Below methods illustrates the working of ready() method:
Program 1:
// Java program to demonstrate // PushbackReader ready() method import java.io.*; import java.util.*; class GFG { public static void main(String[] args) { try { // Initializing a StringReader // and PushbackReader String s = "GeeksForGeeks"; StringReader stringReader = new StringReader(s); PushbackReader pushbackReader = new PushbackReader(stringReader); // Check if the PushbackReader is // ready to be read using ready() System.out.println("Is PushbackReader ready " + "to be read: " + pushbackReader.ready()); // Close the stream using ready() pushbackReader.close(); System.out.println("Stream Closed."); } catch (Exception e) { System.out.println(e); } } } |
Is PushbackReader ready to be read: true Stream Closed.
Program 2:
// Java program to demonstrate // PushbackReader ready() method import java.io.*; import java.util.*; class GFG { public static void main(String[] args) { try { // Initializing a StringReader // and PushbackReader String s = "GFG"; StringReader stringReader = new StringReader(s); PushbackReader pushbackReader = new PushbackReader(stringReader); // Check if the PushbackReader is // ready to be read using ready() System.out.println("Is PushbackReader ready " + "to be read: " + pushbackReader.ready()); // Close the stream pushbackReader.close(); System.out.println("Stream Closed."); } catch (Exception e) { System.out.println(e); } } } |
Is PushbackReader ready to be read: true Stream Closed.
Reference: https://docs.oracle.com/javase/9/docs/api/java/io/PushbackReader.html#ready–
Recommended Posts:
- PushbackReader reset() method in Java with Examples
- PushbackReader close() method in Java with Examples
- PushbackReader mark(int) method in Java with Examples
- PushbackReader read() method in Java with Examples
- PushbackReader markSupported() method in Java with Examples
- Reader ready() method in Java with Examples
- StringReader ready() method in Java with Examples
- CharArrayReader ready() method in Java with Examples
- PushbackReader read(char, int, int) method in Java with Examples
- PushbackReader skip(long) method in Java with Examples
- Java.io.PushbackReader Class in Java
- Java lang.Long.reverse() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



