开发者

How do you "empty" a StringWriter in Java?

What is the correct way to "empty" a StringWriter in Java so that I can reuse the StringWriter without having 开发者_StackOverflowto create a new one? Neither StringWriter.flush() nor StringWriter.close() seem to have the desired effect.


How about calling getBuffer().setLength(0)?


Alternatively, we could also delete the buffer using the following code:

StringBuffer buf = ****.getBuffer();
buf.delete(0,buf.length());
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜