|
JavaTM 2 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 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。