Most visited

Recently visited

Added in API level 1

StringWriter

public class StringWriter
extends Writer

java.lang.Object
   ↳ java.io.Writer
     ↳ java.io.StringWriter


字符流将其输出收集到字符串缓冲区中,然后可用于构建字符串。

关闭StringWriter不起作用。 在关闭流之后可以调用此类中的方法,而不生成IOException

Summary

Inherited fields

From class java.io.Writer

Public constructors

StringWriter()

使用默认的初始字符串缓冲区大小创建一个新的字符串编写器。

StringWriter(int initialSize)

使用指定的初始字符串缓冲区大小创建一个新的字符串编写器。

Public methods

StringWriter append(char c)

将指定的字符附加到此作者。

StringWriter append(CharSequence csq, int start, int end)

将指定字符序列的子序列附加到此作者。

StringWriter append(CharSequence csq)

将指定的字符序列追加到此作者。

void close()

关闭 StringWriter不起作用。

void flush()

冲洗流。

StringBuffer getBuffer()

返回字符串缓冲区本身。

String toString()

以字符串形式返回缓冲区的当前值。

void write(String str)

写一个字符串。

void write(int c)

写一个字符。

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

编写一部分字符串。

void write(char[] cbuf, int off, int len)

编写一个字符数组的一部分。

Inherited methods

From class java.io.Writer
From class java.lang.Object
From interface java.lang.Appendable
From interface java.io.Closeable
From interface java.io.Flushable
From interface java.lang.AutoCloseable

Public constructors

StringWriter

Added in API level 1
StringWriter ()

使用默认的初始字符串缓冲区大小创建一个新的字符串编写器。

StringWriter

Added in API level 1
StringWriter (int initialSize)

使用指定的初始字符串缓冲区大小创建一个新的字符串编写器。

Parameters
initialSize int: The number of char values that will fit into this buffer before it is automatically expanded
Throws
IllegalArgumentException If initialSize is negative

Public methods

append

Added in API level 1
StringWriter append (char c)

将指定的字符附加到此作者。

表单 out.append(c)的此方法的调用与调用完全相同

     out.write(c) 

Parameters
c char: The 16-bit character to append
Returns
StringWriter This writer

append

Added in API level 1
StringWriter append (CharSequence csq, 
                int start, 
                int end)

将指定字符序列的子序列附加到此作者。

形式的这种方法的调用时 out.append(csq, start, end) csq不是 null,行为以完全相同的方式调用

     out.write(csq.subSequence(start, end).toString()) 

Parameters
csq CharSequence: The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".
start int: The index of the first character in the subsequence
end int: The index of the character following the last character in the subsequence
Returns
StringWriter This writer
Throws
IndexOutOfBoundsException If start or end are negative, start is greater than end, or end is greater than csq.length()

append

Added in API level 1
StringWriter append (CharSequence csq)

将指定的字符序列追加到此作者。

表单 out.append(csq)的这种方法的调用的行为与调用完全相同

     out.write(csq.toString()) 

取决于toString字符序列csq本说明书中,整个序列可以不追加。 例如,调用字符缓冲区的toString方法将返回一个子序列,其内容取决于缓冲区的位置和限制。

Parameters
csq CharSequence: The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.
Returns
StringWriter This writer

close

Added in API level 1
void close ()

关闭StringWriter不起作用。 可以在关闭流之后调用此类中的方法,而不生成IOException

Throws
IOException

flush

Added in API level 1
void flush ()

冲洗流。

getBuffer

Added in API level 1
StringBuffer getBuffer ()

返回字符串缓冲区本身。

Returns
StringBuffer StringBuffer holding the current buffer value.

toString

Added in API level 1
String toString ()

以字符串形式返回缓冲区的当前值。

Returns
String a string representation of the object.

write

Added in API level 1
void write (String str)

写一个字符串。

Parameters
str String: String to be written

write

Added in API level 1
void write (int c)

写一个字符。

Parameters
c int: int specifying a character to be written

write

Added in API level 1
void write (String str, 
                int off, 
                int len)

编写一部分字符串。

Parameters
str String: String to be written
off int: Offset from which to start writing characters
len int: Number of characters to write

write

Added in API level 1
void write (char[] cbuf, 
                int off, 
                int len)

编写一个字符数组的一部分。

Parameters
cbuf char: Array of characters
off int: Offset from which to start writing characters
len int: Number of characters to write

Hooray!