Readers Writers  «Prev  Next»


Lesson 12 CharArrayWriter class
Objective Explore the CharArrayWriter class constructors and methods.

CharArrayWriter class

Constructors

The CharArrayWriter class, like the CharArrayReader class, also has two constructors. The first constructor constructs a writer that writes into an internal array of chars. The second specifies the initial size of that internal array of chars. However, in both cases the array can grow as necessary.

public CharArrayWriter()

public CharArrayWriter(int initialSize)

Methods

You can return this array as either an array of chars or as a String using the toCharArray() or toString() methods respectively.

public char[] toCharArray()

public String toString()

You can determine how big the internal buffer is with the size() method.
public int size()

The writeTo() method copies the char array to a different Writer object.
public void writeTo(Writer out) throws IOException

Finally, the CharArrayWriter class has the usual writer methods:

  1. write(),
  2. close(), and
  3. flush().

Readers Writers - Quiz

Click the Quiz to take a brief multiple-choice quiz covering string readers and writers, piped readers and writers, PrintWriters, and filtered readers and writers.
Readers Writers - Quiz