无法使用Zip4J在java中解压缩

无法使用Zip4J在java中解压缩,java,zip,Java,Zip,你好,我来自中国彼岸的太平洋。 请原谅我的初级英语。 屏蔽外国网站会带来更多问题 在我当前的项目中,我正在使用zip4j,但出现了一个问题。这是我的密码: public static File [] unzip(File zipFile, String dest, String passwd) throws ZipException { ZipFile zFile = new ZipFile(zipFile); zFile.setFileNameCharset("GBK");

你好,我来自中国彼岸的太平洋。 请原谅我的初级英语。 屏蔽外国网站会带来更多问题

在我当前的项目中,我正在使用zip4j,但出现了一个问题。这是我的密码:

public static File [] unzip(File zipFile, String dest, String passwd) throws ZipException {
    ZipFile zFile = new ZipFile(zipFile);
    zFile.setFileNameCharset("GBK");
    if (!zFile.isValidZipFile()) {
        throw new ZipException("压缩文件不合法,可能被损坏.");
    }
    File destDir = new File(dest);
    if (destDir.isDirectory() && !destDir.exists()) {
        destDir.mkdir();
    }
    if (zFile.isEncrypted()) {
        zFile.setPassword(passwd.toCharArray());
    }
    zFile.extractAll(dest);

    List<FileHeader> headerList = zFile.getFileHeaders();
    List<File> extractedFileList = new ArrayList<File>();
    for(FileHeader fileHeader : headerList) {
        if (!fileHeader.isDirectory()) {
            extractedFileList.add(new File(destDir,fileHeader.getFileName()));
        }
    }
    File [] extractedFiles = new File[extractedFileList.size()];
    extractedFileList.toArray(extractedFiles);
    return extractedFiles;
}

用于创建您试图提取的ZIP文件的工具是什么

很可能您的zip文件已损坏。请使用Winzip(Windows)或GUnzip(UNIX)等解压工具尝试解压,以检查它是否已损坏


如果它没有损坏,则很可能使用Zip4J不支持的加密方法对zip进行加密和密码保护。例如,Zip4J支持AES-256位Winzip加密/解密,但不支持AES-256 PKZIP加密/解密

文件没有损坏,用其他解压工具可以正常解压,在Java测试类中也可以调用此方法也可以正常解压,项目在Linux环境下可以解压,但在Windows环境下出现错误。谢谢你的回答,再次期待你的回答。总是同一个文件导致错误吗?您的文件有多大?可能您的服务器内存已达到限制?
com.ninemax.cul.util.CompressUtil.unzip(CompressUtil.java:68)
:这一行是什么?如果只是windows,可能会出现一些编码问题?你是如何读/写这些文件的?您使用的是
PrintWriter
还是
PrintReader
?它们采用系统默认编码。另外:
在Windows环境中出现错误
-即使您正常解压它们(使用像7z这样的Windows程序)?
net.lingala.zip4j.exception.ZipException: Compressed file is not valid, can be damaged.
    at com.ninemax.cul.util.CompressUtil.unzip(CompressUtil.java:68)
    at com.ninemax.cul.util.CompressUtil.unzip(CompressUtil.java:38)
    at com.ninemax.cul.service.impl.SysShangChuanWenWuService.writeDataToDatabase(SysShangChuanWenWuService.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:311)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy48.writeDataToDatabase(Unknown Source)
    at com.ninemax.cul.action.web.UserUploadAction.uploadSuccess(UserUploadAction.java:93)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)