CharArrayReader In Java Example
Chapter:
Java I/O
Last Updated:
21-07-2016 17:51:37 UTC
Program:
/* ............... START ............... */
import java.io.CharArrayReader;
public class JavaCharArrayReader {
public static void main(String[] args) {
try {
char c[] = { 'J', 'A', 'V', 'A', 'S', 'C', 'A', 'N' };
CharArrayReader charReader = new CharArrayReader(c);
int i;
while ((i = charReader.read()) != -1) {
System.out.print((char) i);
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
/* ............... END ............... */
Output
Notes:
-
The java.io.CharArrayReader.read() method reads a single character. If the stream ends, it returns -1.
- CharArrayReader is an implementation of an input stream that uses a character array as the source. This class has two constructors, each of which requires a character array to provide the data source.
Tags
CharArrayReader, Java, Java I/O