我们可以将字节数组转换为Java中的InputStream吗?我一直在网上看,但找不到它。
我有一个以InputStream为参数的方法。
我的InputStream cph
是base64编码所以我必须使用
BASE64Decoder decoder = new BASE64Decoder();
byte[] decodedBytes = decoder.decodeBuffer(cph);
现在如何将decodedBytes
再次转换为InputStream
?
答案 0 :(得分:280)
InputStream is = new ByteArrayInputStream(decodedBytes);
答案 1 :(得分:4)
如果您使用Robert Harder's Base64 utility,则可以执行以下操作:
InputStream is = new Base64.InputStream(cph);
或者使用太阳的JRE,你可以这样做:
InputStream is = new
com.sun.xml.internal.messaging.saaj.packaging.mime.util.BASE64DecoderStream(cph)
然而,不要依赖那个继续成为JRE一部分的课程,或者甚至继续做它今天似乎做的事情。孙说不要用它。
还有其他关于Base64解码的Stack Overflow问题,例如this one.