|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjava.io.Writer
java.io.CharArrayWriter
public class CharArrayWriter
此類別實作一個可用作 Writer 的字元緩衝區。緩衝區會隨向串流中寫入資料而自動增長。可使用 toCharArray() 和 toString() 獲取資料。
註:在此類別上調用 close() 無效,並且在關閉該串流後可以調用此類別中的各個方法,而不會產生任何 IOException。
| 欄位摘要 | |
|---|---|
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 |
| 欄位詳細資訊 |
|---|
protected char[] buf
protected int count
| 建構子詳細資訊 |
|---|
public CharArrayWriter()
public CharArrayWriter(int initialSize)
initialSize - 一個指定緩衝區初始大小的 int。
IllegalArgumentException - 如果 initialSize 為負。| 方法詳細資訊 |
|---|
public void write(int c)
Writer 中的 writec - 指定要寫入字元的 int。
public void write(char[] c,
int off,
int len)
Writer 中的 writec - 要寫入的資料off - 資料中的起始偏移量len - 寫入的 char 數目
public void write(String str,
int off,
int len)
Writer 中的 writestr - 要寫入的字元串off - 開始讀取字元處的偏移量len - 要寫入的字元數
public void writeTo(Writer out)
throws IOException
out - 要寫入的輸出串流
IOException - 如果發生 I/O 錯誤。public CharArrayWriter append(CharSequence csq)
以 out.append(csq) 形式調用此方法與以下調用具有完全相同的行為:
out.write(csq.toString())
可能不會添加整個序列,這取決於針對字元序列 csq 的 toString 規範。例如,調用一個字元緩衝區的 toString 方法將返回一個子序列,其內容取決於緩衝區的位置和限制。
Appendable 中的 appendWriter 中的 appendcsq - 要添加的字元序列。如果 csq 為 null,則向此 writer 添加四個字元 "null"。
public CharArrayWriter 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 CharArrayWriter append(char c)
以 out.append(c) 形式調用此方法與以下調用具有完全相同的行為:
out.write(c)
Appendable 中的 appendWriter 中的 appendc - 要添加的 16 位字元
public void reset()
public char[] toCharArray()
public int size()
public String toString()
Object 中的 toStringpublic void flush()
Flushable 中的 flushWriter 中的 flushpublic void close()
Closeable 中的 closeWriter 中的 close
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。