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());
精彩评论