CharArrayWriter close() in Java

close(): This method is available in the java.io.CharArrayWriter class of Java.

Syntax:

void java.io.CharArrayWriter.close()

This method closes the stream. This method does not release the buffer, since its contents might still be required.

Parameters: NA

Returns: NA

Exceptions: NA

Approach

Java

import java.io.CharArrayWriter;
import java.io.IOException;

public class CharArrayWriterclose {
    public static void main(String[] args) throws IOException {
        CharArrayWriter charArrayWriter = new CharArrayWriter();

        char cbuf[] = { 'a', 'b', 'c', 'd' };
        charArrayWriter.write(cbuf);

        System.out.println(charArrayWriter.toString());
        charArrayWriter.close();
    }
}

Output:

abcd


No comments:

Post a Comment