Output stream over a StringBuilder

This question already has an answer here:

  • Get an OutputStream into a String 5 answers

  • So you are wanting output written to the stream to go to a StringBuffer instead. I am assuming you are doing this because an OutputStream is required somewhere else. You could use ByteArrayOutputStream, but if you want to preserve the StringBuffer behavior, you might simply wrap a StringBuffer in a subclass of OutputStream like the code here:

    http://geronimo.apache.org/maven/specs/geronimo-javamail_1.4_spec/1.6/apidocs/src-html/org/apache/geronimo/mail/util/StringBufferOutputStream.html#line.31


    使用ByteArrayOutputStream,然后调用toString(charSet) - 不需要StringBuilder。

    链接地址: http://www.djcxy.com/p/78440.html

    上一篇: 我如何规范Java中的EOL字符?

    下一篇: 通过StringBuilder输出流