繁体   English   中英

Java无法解压缩apache Web服务器目录中的文件-java.util.zip.ZipError:找不到zip END标头

[英]Java can't unzip files inside apache web server directory - java.util.zip.ZipError: zip END header not found

我在将Java应用程序解压缩到apache服务器上的文件时遇到了奇怪的问题。 我有一个apache服务器,其中一些其他应用程序上载zip文件。 例如,目录是/ var / www / html / fles

现在,当我启动Java程序来解压缩文件时,它总是失败,但以下异常除外。

我还使用Files.probeContentType(file)检查了contentType,并惊讶地返回了text/plain而不是application/zip ,然后我在另一个目录(例如主目录)中测试了代码,在那里它可以正常工作。

因此,似乎它与apache配置有关,但是我已经检查并禁用了zip文件的gzip压缩功能:我不知道我还需要做什么

我的deflate.conf:

<IfModule mod_deflate.c>
        <IfModule mod_filter.c>
                # these are known to be safe with MSIE 6
                AddOutputFilterByType DEFLATE text/html text/plain text/xml

                # everything else may cause problems with MSIE 6
                AddOutputFilterByType DEFLATE text/css
                AddOutputFilterByType DEFLATE application/x-javascript application/javascript $
                AddOutputFilterByType DEFLATE application/rss+xml
                AddOutputFilterByType DEFLATE application/xml

                SetOutputFilter DEFLATE
                SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png|zip)$" no-gzip
        </IfModule>
</IfModule>

用于创建zip文件系统的Java代码:创建文件系统时已经发生了一些异常:

 private static FileSystem createZipFileSystem(Path zipFilename,
            boolean create)
            throws IOException {
        // convert the filename to a URI

        final URI uri = URI.create("jar:file:" + zipFilename.toUri().getPath());

        final Map<String, String> env = new HashMap<>();
        if (create) {
            env.put("create", "true");
        }
        return FileSystems.newFileSystem(uri, env);
    }

我得到的例外:

  java.util.zip.ZipError: zip END header not found
            at com.sun.nio.zipfs.ZipFileSystem.zerror(ZipFileSystem.java:1605)
            at com.sun.nio.zipfs.ZipFileSystem.findEND(ZipFileSystem.java:1021)
            at com.sun.nio.zipfs.ZipFileSystem.initCEN(ZipFileSystem.java:1030)
            at com.sun.nio.zipfs.ZipFileSystem.<init>(ZipFileSystem.java:130)
            at com.sun.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:117)
            at java.nio.file.FileSystems.newFileSystem(FileSystems.java:326)
            at java.nio.file.FileSystems.newFileSystem(FileSystems.java:276)

我发现问题不是与解压缩有关,而是过了一会儿才意识到我遇到了如下所述的问题: 在写入文件之前触发了Java 7 Watch Service ENTRY_CREATE

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM