繁体   English   中英

java.io.FileNotFoundException-zip4j

[英]java.io.FileNotFoundException - zip4j

我试图创建一个简单的Java程序,尝试用zip4j解压缩zip文件。 但是每次我得到一个java.io.FileNotFoundException。 我不知道为什么,因为该路径存在并且该文件是可写的Java。 压缩文件也没有损坏。

我使用最新的zip4j库运行最新的jdk。 一切都正确实现。 我试图解压缩仅包含一个罐子的拉链,并且可以正常工作。 但是包含更多文件的zip文件失败。

Iam是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库?

我找到了一个简单的解决方法来解压缩文件@ 什么是压缩/解压缩文件的良好Java库?

unzip("path/to/SORUCE.zip", "path/to/destinationfolder");

public void unzip(String source, String dest) throws IOException {
    java.util.zip.ZipFile zipFile = new ZipFile(source);
    try {
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            File entryDestination = new File(dest, entry.getName());
            if (entry.isDirectory()) {
                entryDestination.mkdirs();
            } else {
                entryDestination.getParentFile().mkdirs();
                InputStream in = zipFile.getInputStream(entry);
                OutputStream out = new FileOutputStream(entryDestination);
                IOUtils.copy(in, out);
                IOUtils.closeQuietly(in);
                out.close();
            }
        }
    } finally {
        zipFile.close();
    }
}

暂无
暂无

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

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