Java CharArrayWriter.writewriteTo(Writer out)方法範例
CharArrayWriter
的CharArrayWriter.write(String str, int off, int len)
方法的語法如下。
public void writeTo(Writer out) throws IOException
在下面的程式碼中展示了如何使用CharArrayWriter.writeTo(Writer out)
方法。
import java.io.CharArrayWriter;
public class Main {
public static void main(String[] args) throws Exception {
String str = "from tw511.com!";
CharArrayWriter chw = new CharArrayWriter();
// create destination character array writer
CharArrayWriter chwd = new CharArrayWriter();
chw.write(str); // from:w w W .Y iI b AI . COM
chw.writeTo(chwd);
// print the destination buffer content as string
System.out.println(chwd.toString());
}
}
上面的程式碼生成以下結果。
from tw511.com!