当zip文件包含2GB txt文件时,无法提取该文件引发错误java.util.zip.ZipException:压缩方法无效

当zip文件包含2GB txt文件时,无法提取该文件引发错误java.util.zip.ZipException:压缩方法无效,java,unzip,Java,Unzip,我有解压代码,可以提取,如果zip文件有1.90 GB的txt文件初始化。 但当zip文件包含2GB文本文件时无法解压缩 此处代码: /** *方法将zip文件解压缩到2GB附近,但不超过此值。 *提供zip文件路径和输出文件夹所有解压文件 *将被复制到输出文件夹 */ } 你能提供你的代码,以及你正在使用的JDK版本吗?2GB的限制表明这可能是一个HD编码类型的问题(ntfs,fat32..)。嗨,伯杰,我使用的是64位机器,JDK版本是8。我添加了代码片段。您正在神奇地将unZipIt()中

我有解压代码,可以提取,如果zip文件有1.90 GB的txt文件初始化。 但当zip文件包含2GB文本文件时无法解压缩

此处代码: /** *方法将zip文件解压缩到2GB附近,但不超过此值。 *提供zip文件路径和输出文件夹所有解压文件 *将被复制到输出文件夹 */

}


你能提供你的代码,以及你正在使用的JDK版本吗?2GB的限制表明这可能是一个HD编码类型的问题(ntfs,fat32..)。嗨,伯杰,我使用的是64位机器,JDK版本是8。我添加了代码片段。您正在神奇地将
unZipIt()
中声明的局部变量
ze
清除为null或不为null或不同,因为在方法
writeExtractedFile()
中声明的局部变量
ze
被赋值为不同的变量。它不会那样做的。您需要将
zis.getnextery()
调用移动到
unZipIt()
方法中。执行上述操作后,将不会更改结果。
public void unZipIt(String zipFile, String outputFolder)  {
    // create output directory is not exists
    File folder = new File(outputFolder);
    if (!folder.exists()) {
        folder.mkdir();
    }
    //extract zip if already present skip file from extraction
    try (ZipInputStream zis = new ZipInputStream(new FileInputStream(
            zipFile));) {

        ZipEntry ze = zis.getNextEntry();
        while (ze != null) {

            String fileName = ze.getName();
            File newFile = new File(outputFolder + File.separator
                    + fileName);
            if (!newFile.exists()) {
                new File(newFile.getParent()).mkdirs();
                ze = writeExtractedFile(zis, newFile);
                AutoLog.getLogger().info("File extracted: "+fileName);
            }
            else
            {
                AutoLog.getLogger().info("File aready present in directory so skip file:"+fileName);
                ze=zis.getNextEntry();
            }
        }
        zis.closeEntry();
    } catch (IOException e) {
        Assert.fail("Fail to unzip zip file", e);
    }
/**
 * helper method for zip extract 
 * new created file in output folder this method will write the same data 
 * to this files. 
 */
private ZipEntry writeExtractedFile(ZipInputStream zis,
        File newFile) {
    byte[] buffer = new byte[10]; 
    ZipEntry ze = null;
    try (FileOutputStream fos = new FileOutputStream(newFile)) {
        int len;
        while ((len = zis.read(buffer)) > 0) {
            fos.write(buffer, 0, len);
        }
        ze = zis.getNextEntry();
        return ze;
    } catch (Exception e) {
        Assert.fail("Fail to write extracted file", e);
    }
    return ze;

}