Skip to main content

CharArrayWriter class in java is a class in java programming language. Inside of this class exists 13 public methods. Declaration of this class as follows.

public class 

CharArrayWriter public method

There are following useful methods which is define the inside of class.

CharArrayWriter append(char c) It appends the specified character to this writer.
CharArrayWriter append(CharSequence csq) It appends the specified character sequence to this writer.
CharArrayWriter append(CharSequence csq, int start, int end) It appends a subsequence of the specified character sequence to this writer.
void close() It close the stream.
void flush() It flush the stream.
void reset() It resets the buffer so that you can use it again without throwing away the already allocated buffer.
int size() It returns the current size of the buffer.
char[] toCharArray() It returns a copy of the input data.
String toString() It converts input data to a string.
void write(char[] c, int off, int len) It writes characters to the buffer.
void write(int c) It writes a character to the buffer.
void write(String str, int off, int len) It write a portion of a string to the buffer.
void writeTo(Writer out) It writes the contents of the buffer to another character stream.

This reference is belong to javadoc

Public Constructors

There is 2 types of public constructor is defined inside the class, Whose syntax as follows.


Example of CharArrayWriter() constructor.

// java program for CharArrayWriter
public class Example
    public static void main(String[] args) throws Exception
        // Create an instance
        CharArrayWriter w = new CharArrayWriter();
        w.write("I like this logic");
        // Create FileWriter instance
        FileWriter file = new FileWriter("file.txt");
        // Put value into file
Instance of class in java
File : file.txt
Contain : I like this logic


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment