Convert Contents Of A ByteArrayInputStream To String

后端 未结 5 999
盖世英雄少女心
盖世英雄少女心 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:48

    Use Base64 encoding

    Assuming you got your ByteArrayOutputStream :

    ByteArrayOutputStream baos =...
    String s = new String(Base64.Encoder.encode(baos.toByteArray()));
    

    See http://docs.oracle.com/javase/8/docs/api/java/util/Base64.Encoder.html

提交回复
热议问题