Java Reader.read(char[] cbuf)
Syntax
Reader.read(char[] cbuf) has the following syntax.
public int read(char[] cbuf) throws IOException
Example
In the following code shows how to use Reader.read(char[] cbuf) method.
/*ww w . j a va 2 s . c o m*/
import java.io.*;
public class Main {
public static void main(String[] args) {
String s = "tutorial from java2s.com";
Reader reader = new StringReader(s);
// create a char array to read chars into
char cbuf[] = new char[5];
try {
// read characters into an array.
System.out.println(reader.read(cbuf));
System.out.println(cbuf);
reader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »