CharArrayWriter class in java

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

public class java.io.CharArrayWriter 
extends java.io.Writer 

CharArrayWriter public method

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

MethodDescription
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.

public java.io.CharArrayWriter()
public java.io.CharArrayWriter(int)

Example of CharArrayWriter() constructor.

// java program for CharArrayWriter
import java.io.CharArrayWriter;
import java.io.FileWriter;
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
        w.writeTo(file);
        file.close();
        w.close();
    }
}
Instance of java.io.CharArrayWriter 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







© 2021, kalkicode.com, All rights reserved