public class StringWriter extends Writer
关闭StringWriter没有影响。这个类中的方法可以在流一直没有产生一个IOException闭叫。
Constructor and Description |
---|
StringWriter()
使用默认的初始字符串缓冲区大小创建一个新的字符串写作者。
|
StringWriter(int initialSize)
使用指定的初始字符串缓冲区大小创建一个新的字符串写作者。
|
Modifier and Type | Method and Description |
---|---|
StringWriter |
append(char c)
将指定的字符到这个作家。
|
StringWriter |
append(CharSequence csq)
将指定的字符序列,这个作家。
|
StringWriter |
append(CharSequence csq, int start, int end)
添加一个序列指定的字符序列,这个作家。
|
void |
close()
关闭
StringWriter没有影响。
|
void |
flush()
冲洗流。
|
StringBuffer |
getBuffer()
返回字符串缓冲区本身。
|
String |
toString()
返回缓冲区的当前值作为字符串。
|
void |
write(char[] cbuf, int off, int len)
写一个字符数组的一部分。
|
void |
write(int c)
写一个字符。
|
void |
write(String str)
写一个字符串。
|
void |
write(String str, int off, int len)
写一个字符串的一部分。
|
public StringWriter()
public StringWriter(int initialSize)
initialSize
-
char值的个数,将融入这个缓冲区之前,它是自动扩展
IllegalArgumentException
-如果
initialSize是负的
public void write(char[] cbuf, int off, int len)
public void write(String str, int off, int len)
public StringWriter append(CharSequence csq)
这种形式的out.append(csq)方法调用的行为一样,调用
写出来。(CSQ。tostring())
根据字符序列的csq toString规范,整个序列可能不追加。例如,调用字符缓冲区的toString方法将返回一个序列的内容取决于缓冲区的位置和范围。
append
接口
Appendable
append
方法重写,继承类
Writer
csq
-字符序列添加。如果
csq是
null,然后四个字
"null"附加到这个作家。
public StringWriter append(CharSequence csq, int start, int end)
这种形式的out.append(csq, start, end)当csq不null方法调用,表现在完全相同的方式调用
写出来。(CSQ。子序列(开始、结束)。tostring())
append
接口
Appendable
append
方法重写,继承类
Writer
csq
-字符序列的子序列将追加。如果
csq是
null,那么人物将追加好像
csq包含四个字符
"null"。
start
-子序列中的第一个字符的索引
end
-子序列中的最后一个字符后的字符的索引
IndexOutOfBoundsException
-如果
start或
end是负面的,
start大于
end,或
end大于
csq.length()
public StringWriter append(char c)
这种形式的out.append(c)方法调用的行为一样,调用
外写(c)
append
接口
Appendable
append
方法重写,继承类
Writer
c
- 16位字符追加
public StringBuffer getBuffer()
public void close() throws IOException
close
接口
Closeable
close
接口
AutoCloseable
close
方法重写,继承类
Writer
IOException
如果I/O错误发生
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.