Java CharArrayReader.read()
Syntax
CharArrayReader.read() has the following syntax.
public int read() throws IOException
Example
In the following code shows how to use CharArrayReader.read() method.
/*from w w w. j ava 2 s. c om*/
import java.io.CharArrayReader;
public class Main {
public static void main(String[] args) throws Exception {
char[] ch = { 'H', 'E', 'L', 'L', 'O' };
CharArrayReader car = new CharArrayReader(ch);
int value = 0;
// read till the end of the file
while ((value = car.read()) != -1) {
char c = (char) value;
// print the character
System.out.print(c + " : ");
// print the integer
System.out.println(value);
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »