使用 JAVA 中的输入流解压缩加密的 zip 文件



需要一个Java解决方案来使用输入流解压缩一个大文件(不适合内存(。在这种情况下,文件对象不可用。该文件受密码保护。带有文件对象的解决方案将无济于事。

我已经尝试过使用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();
    }

我也有这样的问题。在此存储库(https://github.com/r331/memzipenc(中,您可以找到一个方法MemZipDec.unzipFiles(byte[] zipBytes,字符串密码(我希望这会有所帮助。

最新更新