?? chararraywriterdemo.java
字號:
package chararraywriter;
/**
CharArrayWriter 實現了以數組作為目標的輸出流。CharArrayWriter 有兩個構造函數:
CharArrayWriter( )
CharArrayWriter(int numChars)
第一種形式,創建了一個默認長度的緩沖器。第二種形式,緩沖器長度由numChars指
定。緩沖器保存在CharArrayWriter的buf 成員中。緩沖器大小在需要的情況下可以自動增
長。緩沖器保持的字符數包含在CharArrayWriter的count 成員中。buf 和count 都是受保護
的域。
下面的例子闡述了CharArrayWriter,我們繼續使用前面顯示的ByteArrayOutputStream
例子中演示的程序。它的輸出與以前的例子輸出相同:
Buffer as a string
This should end up in the array
Into array
This should end up in the array
To a FileWriter()
Doing a reset
XXX
*/
// Demonstrate CharArrayWriter.
import java.io.*;
class CharArrayWriterDemo {
public static void main(String args[]) throws IOException {
CharArrayWriter f = new CharArrayWriter();
String s = "This should end up in the array";
char buf[] = new char[s.length()];
s.getChars(0, s.length(), buf, 0);
f.write(buf);
System.out.println("Buffer as a string");
System.out.println(f.toString());
System.out.println("Into array");
char c[] = f.toCharArray();
for (int i = 0; i < c.length; i++) {
System.out.print(c[i]);
}
System.out.println("\nTo a FileWriter()");
FileWriter f2 = new FileWriter("test.txt");
f.writeTo(f2);
f2.close();
System.out.println("Doing a reset");
f.reset();
for (int i = 0; i < 3; i++) {
f.write('X');
}
System.out.println(f.toString());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -