在Java 1.5中,如何克隆java.io.CharArrayWriter的實例?如何克隆CharArrayWriter?
CharArrayWriter x = new CharArrayWriter(200);
x.write("foo bar bob");
CharArrayWriter y = x.clone(); // Object.clone() is not visible!!
感謝,
mobiGeek
在Java 1.5中,如何克隆java.io.CharArrayWriter的實例?如何克隆CharArrayWriter?
CharArrayWriter x = new CharArrayWriter(200);
x.write("foo bar bob");
CharArrayWriter y = x.clone(); // Object.clone() is not visible!!
感謝,
mobiGeek
沒有clone方法,但你可以用writeTo
方法。
CharArrayWriter copy = new CharArrayWriter(x.size());
x.writeTo(copy);
太棒了!謝謝! – mobiGeek 2009-12-11 03:43:30