📜  Java.io.CharArrayWriter类

📅  最后修改于: 2020-11-15 02:40:04             🧑  作者: Mango


介绍

Java.io.CharArrayWriter类实现了可用作Writer的字符缓冲区。将数据写入流时,缓冲区会自动增长。

类声明

以下是Java.io.CharArrayWriter类的声明-

public class CharArrayWriter
   extends Writer

领域

以下是Java.io.CharArrayWriter类的字段-

  • protected char [] buf-这是存储数据的缓冲区。

  • protected int count-这是缓冲区中的字符数。

  • protected Object lock-这是用于同步此流上的操作的对象。

类的构造函数

Sr.No. Constructor & Description
1

CharArrayWriter()

This creates a CharArrayReader from the specified array of chars.

2

CharArrayWriter(int initialSize)

This creates a new CharArrayWriter with the specified initial size.

类方法

Sr.No. Method & Description
1 CharArrayWriter append(char c)

This method appends the specified character to this writer.

2 CharArrayWriter append(CharSequence csq)

This method appends the specified character sequence to this writer.

3 CharArrayWriter append(CharSequence csq, int start, int end)

This method appends a subsequence of the specified character sequence to this writer.

4 void close()

This method close the stream.

5 void flush()

This method flush the stream.

6 void reset()

This method resets the buffer so that you can use it again without throwing away the already allocated buffer.

7

int size()

This method returns the current size of the buffer.

8 char[] toCharArray()

This method returns a copy of the input data.

9 String toString()

This method converts input data to a string.

10 void write(char[] c, int off, int len)

This method writes characters to the buffer.

11 void write(int c)

This method writes a character to the buffer.

12 void write(String str, int off, int len)

This method write a portion of a string to the buffer.

13 void writeTo(Writer out)

This method writes the contents of the buffer to another character stream.

方法继承

此类从以下类继承方法-

  • Java.io.作家
  • Java对象