ZipOutputStream转InputStream
时间: 2023-10-22 20:18:53 浏览: 41
JAVA文件压缩与解压缩实践(源代码).zip
可以使用ByteArrayOutputStream来将ZipOutputStream的内容存储,并且通过ByteArrayInputStream来返回InputStream对象。具体实现代码如下:
```
public static InputStream zipOutputStreamToInputStream(ZipOutputStream zipOutputStream) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = zipOutputStream.read(buffer)) > 0) {
baos.write(buffer, 0, len);
}
zipOutputStream.close();
return new ByteArrayInputStream(baos.toByteArray());
}
```
阅读全文