|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.io.Writer
java.io.StringWriter
public class StringWriter
一个字符流,可以用其回收在字符串缓冲区中的输出来构造字符串。
关闭 StringWriter 无效。此类中的方法在关闭该流后仍可被调用,而不会产生任何 IOException。
| 字段摘要 |
|---|
| 从类 java.io.Writer 继承的字段 |
|---|
lock |
| 构造方法摘要 | |
|---|---|
StringWriter()
使用默认初始字符串缓冲区大小创建一个新字符串 writer。 |
|
StringWriter(int initialSize)
使用指定初始字符串缓冲区大小创建一个新字符串 writer。 |
|
| 方法摘要 | |
|---|---|
StringWriter |
append(char c)
将指定字符添加到此 writer。 |
StringWriter |
append(CharSequence csq)
将指定的字符序列添加到此 writer。 |
StringWriter |
append(CharSequence csq,
int start,
int end)
将指定字符序列的子序列添加到此 writer。 |
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)
写入字符串的某一部分。 |
| 从类 java.io.Writer 继承的方法 |
|---|
write |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 构造方法详细信息 |
|---|
public StringWriter()
public StringWriter(int initialSize)
initialSize - 在此缓冲区自动扩展前适合它的 char 值数。
IllegalArgumentException - 如果 initialSize 为负| 方法详细信息 |
|---|
public void write(int c)
Writer 中的 writec - 指定要写入字符的 int。
public void write(char[] cbuf,
int off,
int len)
Writer 中的 writecbuf - 字符数组off - 开始写入字符处的偏移量len - 要写入的字符数public void write(String str)
Writer 中的 writestr - 要写入的字符串
public void write(String str,
int off,
int len)
Writer 中的 writestr - 要写入的字符串off - 开始写入字符处的偏移量len - 要写入的字符数public StringWriter append(CharSequence csq)
以 out.append(csq) 的形式调用此方法,行为与以下调用完全相同:
out.write(csq.toString())
可能不添加整个序列,也可能添加,具体取决于字符序列 csq 的 toString 指定。例如,调用一个字符缓冲区的 toString 方法将返回一个子序列,其内容取决于缓冲区的位置和限制。
Appendable 中的 appendWriter 中的 appendcsq - 要添加的字符串序列。如果 csq 为 null,则向此 writer 添加四个字符 "null"。
public StringWriter append(CharSequence csq,
int start,
int end)
当 csq 不为 null 时,调用该方法的 out.append(csq、 start、 end) 形式,行为与以下调用完全相同:
out.write(csq.subSequence(start, end).toString())
Appendable 中的 appendWriter 中的 appendcsq - 子序列将被添加的字符序列。如果 csq 为 null,则添加四个字符 "null",就好像 csq 包含它们一样。start - 子序列中第一个字符的索引end - 子序列中最后一个字符后面的字符的索引
IndexOutOfBoundsException - 如果 start 或 end 为负,而 start 大于 end 或者 end 大于 csq.length()。public StringWriter append(char c)
以 out.append(c) 的形式调用此方法,行为与以下调用完全相同:
out.write(c)
Appendable 中的 appendWriter 中的 appendc - 要添加的 16 位字符
public String toString()
Object 中的 toStringpublic StringBuffer getBuffer()
public void flush()
Flushable 中的 flushWriter 中的 flush
public void close()
throws IOException
Closeable 中的 closeWriter 中的 closeIOException - 如果发生 I/O 错误
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。