Java BufferedReader.ready()
Syntax
BufferedReader.ready() has the following syntax.
public boolean ready() throws IOException
Example
In the following code shows how to use BufferedReader.ready() method.
//from ww w . ja v a 2 s . com
import java.io.BufferedReader;
import java.io.StringReader;
import java.nio.CharBuffer;
public class Main {
public static void main(String[] args) throws Exception {
String s = "from java2s.com";
StringReader sr = new StringReader(s);
// create new buffered reader
BufferedReader br = new BufferedReader(sr);
// Destination source is created
CharBuffer target = CharBuffer.allocate(s.length());
// ready is invoked to test if character stream is ready
if (br.ready()) {
br.read(target);
}
System.out.print(target.array());
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »