[英]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.