Convert Contents Of A ByteArrayInputStream To String

后端 未结 5 1040
盖世英雄少女心
盖世英雄少女心 2020-12-30 23:11

I read this post but I am not following. I have seen this but have not seen a proper example of converting a ByteArrayInputStream to String using

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 23:45

    Why nobody mentioned org.apache.commons.io.IOUtils?

    import java.nio.charset.StandardCharsets;
    import org.apache.commons.io.IOUtils;
    
    String result = IOUtils.toString(in, StandardCharsets.UTF_8);
    

    Just one line of code.

提交回复
热议问题