Topics Index

Input/Output: Exploring > Character Streams >
Siva Nookala - 15 Apr 2016
CharArrayReader is a subclass of Reader Class In Java. It implements a character buffer that can be used as a character-input stream.

Constructors :
Constructor Description
CharArrayReader(char[] buf) Creates a CharArrayReader from the specified array of chars.
CharArrayReader(char[] buf, int offset, int length) Creates a CharArrayReader from the specified array of chars.
Important Methods :
Methods Description
boolean ready() Tells whether this stream is ready to be read.
int read() Reads a single character.
boolean markSupported() Tells whether this stream supports the mark() operation.
void mark(int readAheadLimit) Marks the present position in the stream.
void reset() Resets the stream.
abstract void close() Closes the stream and releases any system resources associated with it.

class CharArrayReaderDemo
    public static void main(String arg[])
        String quote = "Merit Campus -Your Online Java School.";
        char c[] = quote.toCharArray(); // LINE A
        CharArrayReader car = new CharArrayReader(c); // LINE B
        System.out.println("Is ready : " + car.ready()); // LINE C
        int i;
        while( (i = != -1) // LINE D
        car.close(); //    

Is ready : true
Merit Campus -Your Online Java School.


At LINE A we are converting the Sting to charArray.
At LINE B we created a CharArrayReader object to read characters from c in a stream manner.
At LINE C we are checking whether stream is ready or not.
At LINE D we are reading character from Stream.
At LINE E we are closing the stream.

  • Convert the String I LOVE PROGRAMMING in to char array and read characters in stream manner..
  • Mark at P in the String and read 4 characters.
  • Reset the stream.
Rest of Methods :
Method Description
abstract int read(char[] cbuf, int off, int len) Reads characters into a portion of an array.
long skip(long n) Skips characters.

Score more than 2 points

© meritcampus 2016 - 2017

All Rights Reserved.