开发者

How to clone a CharArrayWriter?

In Java 1.5, how can I clone开发者_如何学编程 an instance of java.io.CharArrayWriter?

CharArrayWriter x = new CharArrayWriter(200);
x.write("foo bar bob");

CharArrayWriter y = x.clone();   //  Object.clone() is not visible!!

Thanks,

mobiGeek


There is no clone method, but you can use writeTo method.

CharArrayWriter copy = new CharArrayWriter(x.size());
x.writeTo(copy);


CharArrayWriter is not cloneable. Depending on your actual requirement you can do similar with:

CharArrayWriter y = new CharArrayWriter();
y.write( x.toCharArray() );

Which is essentially the same thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜