在Java 1.5中,如何克隆java.io.CharArrayWriter的实例?
CharArrayWriter x = new CharArrayWriter(200);
x.write("foo bar bob");
CharArrayWriter y = x.clone(); // Object.clone() is not visible!!
谢谢,
mobiGeek
答案 0 :(得分:4)
没有克隆方法,但您可以使用writeTo
方法。
CharArrayWriter copy = new CharArrayWriter(x.size());
x.writeTo(copy);
答案 1 :(得分:0)
CharArrayWriter
不可复制。根据您的实际要求,您可以执行以下操作:
CharArrayWriter y = new CharArrayWriter();
y.write( x.toCharArray() );
这基本上是一回事。