java.io.BufferedReader ready()

Description :

This java tutorial shows how to use the ready() method of Scanner class of java.io package. This method returns a boolean data type, true if the buffer is not empty which signifies that the stream is ready to be read otherwise false.

Method Syntax :

public boolean ready() throws IOException

Parameter Input :

DataType Parameter Description
N/A N/A N/A

Method Returns :

This method simply returns true true if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.

Compatibility Version :

Requires Java 1.1 and up

Exception :

None

Discussion :

The BufferedReader ready() method overrides the inherited method of Reader class. This method is used to flag down if the stream is ready to be read.

Java Code Example :

This java example source code demonstrates the use of ready() method of BufferedReader class. Basically the code asks for the user address from the console and then uses the ready method to check if the character stream is ready. If the stream is ready, we then prints out the address using the BufferedReader nextLine() method.

Sample Output :

Running the ready() method example source code of BufferedReader class will give you the following output

Similar Method :

  • N/A

Suggested Reading List :

References :