| |||||||||
摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 |
java.io
类 CharArrayWriter
java.lang.Object java.io.Writer java.io.CharArrayWriter
- 所有已实现的接口:
- Closeable, Flushable, Appendable
public class CharArrayWriter
- extends Writer
此类实现一个可用作 Writer 的字符缓冲区。缓冲区会随向流中写入数据而自动增长。可使用 toCharArray() 和 toString() 检索数据。
注:在此类上调用 close() 无效,并且在关闭该流后可以调用此类中的各个方法,而不会产生任何 IOException。
- 从以下版本开始:
- JDK1.1
字段摘要 | |
---|---|
protected char[] | buf 存储数据的缓冲区。 |
protected int | count 缓冲区中的 char 数目。 |
从类 java.io.Writer 继承的字段 |
---|
lock |
构造方法摘要 | |
---|---|
CharArrayWriter() 创建一个新的 CharArrayWriter。 | |
CharArrayWriter(int initialSize) 创建一个具有指定初始大小的新 CharArrayWriter。 |
方法摘要 | |
---|---|
CharArrayWriter | append(char c) 将指定字符追加到此 writer。 |
CharArrayWriter | append(CharSequence csq) 将指定的字符序列追加到此 writer。 |
CharArrayWriter | append(CharSequence csq, int start, int end) 将指定字符序列的子序列追加到此 writer。 |
void | close() 关闭该流。 |
void | flush() 刷新该流的缓冲。 |
void | reset() 重置该缓冲区,以便再次使用它而无需丢弃已分配的缓冲区。 |
int | size() 返回缓冲区的当前大小。 |
char[] | toCharArray() 返回输入数据的副本。 |
String | toString() 将输入数据转换为字符串。 |
void | write(char[] c, int off, int len) 将字符写入缓冲区。 |
void | write(int c) 将一个字符写入缓冲区。 |
void | write(String str, int off, int len) 将字符串的某一部分写入缓冲区。 |
void | writeTo(Writer out) 将缓冲区的内容写入另一个字符流。 |
从类 java.io.Writer 继承的方法 |
---|
write, write |
从类 java.lang.Object 继承的方法 |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
字段详细信息 |
---|
buf
protected char[] buf
- 存储数据的缓冲区。
count
protected int count
- 缓冲区中的 char 数目。
构造方法详细信息 |
---|
CharArrayWriter
public CharArrayWriter()
- 创建一个新的 CharArrayWriter。
CharArrayWriter
public CharArrayWriter(int initialSize)
- 创建一个具有指定初始大小的新 CharArrayWriter。
- 参数:
initialSize
- 一个指定缓冲区初始大小的 int。- 抛出:
IllegalArgumentException
- 如果 initialSize 为负。
方法详细信息 |
---|
write
public void write(int c)
write
public void write(char[] c, int off, int len)
write
public void write(String str, int off, int len)
writeTo
public void writeTo(Writer out) throws IOException
- 将缓冲区的内容写入另一个字符流。
- 参数:
out
- 要写入的输出流- 抛出:
IOException
- 如果发生 I/O 错误。
append
public CharArrayWriter append(CharSequence csq)
- 将指定的字符序列追加到此 writer。
以 out.append(csq) 形式调用此方法与以下调用具有完全相同的行为:
out.write(csq.toString())
可能不会追加整个序列,这取决于针对字符序列 csq 的 toString 规范。例如,调用一个字符缓冲区的 toString 方法将返回一个子序列,其内容取决于缓冲区的位置和限制。
- 指定者:
- 接口
Appendable
中的append
- 覆盖:
- 类
Writer
中的append
- 参数:
csq
- 要追加的字符序列。如果 csq 为 null,则向此 writer 追加四个字符 "null"。- 返回:
- 此 writer
- 从以下版本开始:
- 1.5