Java CharArrayWriter Class

The CharArrayWriter class can be used to write common data to multiple files. This class inherits Writer class. Its buffer automatically grows when data is written in this stream. Calling the close() method on this object has no effect.


Java CharArrayWriter class declaration

Let's see the declaration for Java.io.CharArrayWriter class:


Java CharArrayWriter class Methods

MethodDescription
int size()It is used to return the current size of the buffer.
char[] toCharArray()It is used to return the copy of an input data.
String toString()It is used for converting an input data to a string.
CharArrayWriter append(char c)It is used to append the specified character to the writer.
CharArrayWriter append(CharSequence csq)It is used to append the specified character sequence to the writer.
CharArrayWriter append(CharSequence csq, int start, int end)It is used to append the subsequence of a specified character to the writer.
void write(int c)It is used to write a character to the buffer.
void write(char[] c, int off, int len)It is used to write a character to the buffer.
void write(String str, int off, int len)It is used to write a portion of string to the buffer.
void writeTo(Writer out)It is used to write the content of buffer to different character stream.
void flush()It is used to flush the stream.
void reset()It is used to reset the buffer.
void close()It is used to close the stream.

Example of CharArrayWriter Class:

In this example, we are writing a common data to 4 files a.txt, b.txt, c.txt and d.txt.

Output

Success...

After executing the program, you can see that all files have common data: Welcome to javaTpoint.

a.txt:

Welcome to javaTpoint

b.txt:

Welcome to javaTpoint

c.txt:

Welcome to javaTpoint

d.txt:

Welcome to javaTpoint




Latest Courses