Can we convert a byte array into an InputStream in Java?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can we convert a byte array into an InputStream in Java? I have been looking on the internet but couldn't find it. I have a method that has an InputStream as argument. The InputStream cph I have is base64 encoded so I had to decode it using BASE64Decoder decoder = new BASE64Decoder(); byte[] decodedBytes = decoder.decodeBuffer(cph); Now how do I convert decodedBytes again to InputStream ? 回答1: Use ByteArrayInputStream : InputStream is = new ByteArrayInputStream(decodedBytes); 回答2: If you use Robert Harder's Base64 utility , then you can do: