Java-CharArrayReader

CharArrayReader

CharArrayReader class contains an internal buffer that can be used as a character-input stream. It inherits Reader class.

CharArrayReader Constructors

Constructors Description
CharArrayReader(char[] buf) Creates a CharArrayReader from a specified character array.
CharArrayReader(char[] buf, int offset, int length) Creates a CharArrayReader from a specified part of character array.

CharArrayReader Methods

Method Description
int read() Reads a single character.
int read(char[] b, int off, int len) Reads characters into a portion of an array.
void mark(int readAheadLimit) Sets the current marked position in the stream. The parameter gives the maximum limit of bytes that can be read before the marked position becomes invalid.
boolean ready() Tells whether this stream is ready to be read.
long skip(long n) Skips characters.
void reset() Resets the stream to the most recent mark, or to the beginning if it has never been marked.
void close() Closes the stream and releases any system resources associated with it.

Program

Program Source

import java.io.CharArrayReader;
import java.io.IOException;

public class Javaapp {
    public static void main(String[] args) throws IOException {
        
        String str = "C++JavaProgrammingPHP";
        CharArrayReader cw = new CharArrayReader(str.toCharArray());
        
        cw.skip(3);
        char ca[] = new char[15];
        cw.read(ca, 0, 15);
        for(char s : ca)
        {
            System.out.print(s);
        }
        cw.close();
    }
}

Leave a Comment