How do you “empty” a StringWriter in Java?

前端 未结 2 1785
无人及你
无人及你 2020-12-29 19:01

What is the correct way to \"empty\" a StringWriter in Java so that I can reuse the StringWriter without having to create a new one? Neither StringWriter.flush

相关标签:
2条回答
  • 2020-12-29 19:21

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

    StringBuffer buf = ****.getBuffer();
    buf.delete(0,buf.length());
    
    0 讨论(0)
  • 2020-12-29 19:24

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

    0 讨论(0)
提交回复
热议问题