我们可以在 Java 中将字节数组转换为 InputStream 吗?

2022-01-21 00:00:00 base64 java inputstream

我们可以在 Java 中将字节数组转换为 InputStream 吗?我一直在网上找,但没找到.

Can we convert a byte array into an InputStream in Java? I have been looking on the internet but couldn't find it.

我有一个以 InputStream 作为参数的方法.

I have a method that has an InputStream as argument.

我拥有的 InputStream cph 是 base64 编码的,所以我必须使用它进行解码

The InputStream cph I have is base64 encoded so I had to decode it using

BASE64Decoder decoder = new BASE64Decoder();
byte[] decodedBytes = decoder.decodeBuffer(cph);

现在如何将 decodedBytes 再次转换为 InputStream?

Now how do I convert decodedBytes again to InputStream?

推荐答案

使用 ByteArrayInputStream:

InputStream is = new ByteArrayInputStream(decodedBytes);

相关文章