java - 使用 JAVA 中的输入流解压缩加密的 zip 文件
问题描述
需要一个 Java 解决方案来使用 inputstream 解压缩一个巨大的文件(不适合内存)。在这种情况下,文件对象不可用。该文件受密码保护。使用 File 对象的解决方案将无济于事。
我已经尝试过 7Zip,但它不支持上述情况。
解决方案
当你使用流时,你不应该读取比需要更多的数据。你试过这个吗?
public void unzip(InputStream is, Cipher cypher) throws IOException {
ZipInputStream zis = new ZipInputStream(new CipherInputStream(is,cypher));
ZipEntry zipEntry = zis.getNextEntry();
byte[] buffer = new byte[1024];
while (zipEntry != null) {
File newFile = new File(zipEntry.getName());
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
zipEntry = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
}
推荐阅读
- node.js - 无法连接到 WebSocket Node.JS
- html - 作为 flex 容器的绝对定位子元素不参与 flex 布局,如何使元素居中?
- java - 如何使用 java 反射迭代对象数组
- java - JAXB 在 Tomcat 9 和 Java 9/10 上不可用
- wpf - WPF MVVM:当 ComboBox SelectedItem 不在 ItemsSource 绑定中时不起作用
- django - 如何将一个应用程序中的所有模型访问到同一个 django 项目中的另一个应用程序
- greenplum - Greenplum数据库二进制包
- cassandra - Cassandra 只是一个存储引擎吗?
- azure-logic-apps - 在哪里可以从我的逻辑应用中为 Azure 服务总线主题订阅提供筛选器
- c# - 将 DLL 转换为 Resx 和反之亦然