How do you “empty” a StringWriter in Java?

前端 未结 2 1787
无人及你
无人及你 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());
    

提交回复
热议问题