我尝试创建一个简单的 Java 程序,它尝试使用 zip4j 解压缩 zip 文件。但是每次我得到一个java.io.FileNotFoundException。我不知道为什么,因为路径存在并且文件可以为 java 写。zip文件也没有损坏。
我使用lates zip4j 库运行最新的jdk。一切都正确实施。我试图解压缩一个只包含一个 jar 的 zip 并且它有效。但是包含更多文件的 zip 失败了。
我是 Java 新手,也是使用 zip4j 的新手。
String enviorment = new File(".").getCanonicalPath();
unzip(enviorment + "/../WITCLASS/cache/dokumentation.zip", enviorment + "/../WITCLASS/cache/");
.zip 文件包括一些 .html 和 .js 文件
private static void unzip(String zipFilePath, String destDir) {
String source = zipFilePath;
String destination = destDir;
String password = "";
try {
ZipFile zipFile = new ZipFile(source);
if (zipFile.isEncrypted()) {
zipFile.setPassword(password);
}
zipFile.extractAll(destination);
} catch (ZipException e) {
e.printStackTrace();
System.out.println(e);
}
}
预期的输出将是:所有文件都成功解压缩。
但我只有:
net.lingala.zip4j.exception.ZipException: net.lingala.zip4j.exception.ZipException: net.lingala.zip4j.exception.ZipException: java.io.FileNotFoundException: /home/user/Downloads/ENGINE/../WITCLASS/cache/dokumentation/example/elements.html (Not a directory)
at net.lingala.zip4j.unzip.Unzip.initExtractFile(Unzip.java:163)
at net.lingala.zip4j.unzip.Unzip.initExtractAll(Unzip.java:83)
at net.lingala.zip4j.unzip.Unzip.extractAll(Unzip.java:73)
at net.lingala.zip4j.core.ZipFile.extractAll(ZipFile.java:488)
at net.lingala.zip4j.core.ZipFile.extractAll(ZipFile.java:451)
at NavigationBar.unzip(NavigationBar.java:329)
at NavigationBar.aptget(NavigationBar.java:205)
at NavigationBar$ScriptBridge.execute(NavigationBar.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at com.sun.webkit.Utilities.lambda$fwkInvokeWithContext$0(Utilities.java:94)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.webkit.Utilities.fwkInvokeWithContext(Utilities.java:94)
at com.sun.webkit.WebPage.twkProcessMouseEvent(Native Method)
at com.sun.webkit.WebPage.dispatchMouseEvent(WebPage.java:807)
at javafx.scene.web.WebView.processMouseEvent(WebView.java:1045)
at javafx.scene.web.WebView.lambda$registerEventHandlers$3(WebView.java:1168)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$5(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:748)
Caused by: net.lingala.zip4j.exception.ZipException: net.lingala.zip4j.exception.ZipException: java.io.FileNotFoundException: /home/user/Downloads/ENGINE/../WITCLASS/cache/dokumentation/example/elements.html (Not a directory)
at net.lingala.zip4j.unzip.UnzipEngine.unzipFile(UnzipEngine.java:98)
at net.lingala.zip4j.unzip.Unzip.initExtractFile(Unzip.java:160)
... 53 more
Caused by: net.lingala.zip4j.exception.ZipException: java.io.FileNotFoundException: /home/user/Downloads/ENGINE/../WITCLASS/cache/dokumentation/example/elements.html (Not a directory)
at net.lingala.zip4j.unzip.UnzipEngine.getOutputStream(UnzipEngine.java:435)
at net.lingala.zip4j.unzip.UnzipEngine.unzipFile(UnzipEngine.java:79)
... 54 more
Caused by: java.io.FileNotFoundException: /home/user/Downloads/ENGINE/../WITCLASS/cache/dokumentation/example/elements.html (Not a directory)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at java.io.FileOutputStream.<init>(FileOutputStream.java:162)
at net.lingala.zip4j.unzip.UnzipEngine.getOutputStream(UnzipEngine.java:432)
... 55 more
我找到如何解压缩的来源: 什么是压缩/解压缩文件的好 Java 库?