开发者

How do you "empty" a StringWriter in Java?

开发者 https://www.devze.com 2023-01-16 09:58 出处:网络
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.cl

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

精彩评论

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

关注公众号