Guava equivalent for IOUtils.toString(InputStream)

前端 未结 9 1135
深忆病人
深忆病人 2020-12-04 16:00

Apache Commons IO has a nice convenience method IOUtils.toString() to read an InputStream to a String.

Since I am trying to move away from Apache Common

9条回答
  •  日久生厌
    2020-12-04 16:37

    If you've got a Readable you can use CharStreams.toString(Readable). So you can probably do the following:

    String string = CharStreams.toString( new InputStreamReader( inputStream, "UTF-8" ) );
    

    Forces you to specify a character set, which I guess you should be doing anyway.

提交回复
热议问题