java - 在java中提取ZIP

标签 java servlets zip4j

各位,

我正在使用 zip4j API 在 java 中提取 .zip 文件,并且能够提取文件

  1. 我曾经使用压缩完整的目录来制作 zip,它包含文件和嵌套目录,使用

    zipFile.addFolder(fileDirectory,parameters);//ZIP目录文件/文件夹

  2. 使用提取 zip

    ZipFile zipFile = new ZipFile(stringArchievedFile);
    //Extracts all files to the path specified
    zipFile.extractAll(stringExtractingFilePath);
    

问题是解压后,文件应该解压到我用 zipFile.extractAll(path) 提供的路径中方法,但正在创建另一个目录。如何将文件解压到实际指定目录

喜欢: 提取路径 C:\提取路径

文件路径 C:\选择路径\文件1

C:\SelectingPath\File2

C:\SelectingPath\Directory1\File1

C:\SelectingPath\Directory2\File1

我将选择C:\SelectingPath目录进行压缩并

我将选择C:\ExtractionPath目录来提取文件

提取后,所有提取的文件将进入

**C:\ExtractionPath\SelectingPath**

我需要目录中的所有文件

**C:\提取路径** 本身。

请帮我解决这个问题。

提前致谢

最佳答案

您尝试一下 Zip4j site 中的示例吗?就像这个:

/*
* Copyright 2010 Srikanth Reddy Lingala  
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
* http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, 
* software distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/

package net.lingala.zip4j.examples.extract;

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;

/**
 * Demonstrates extracting all files from a zip file
 * 
 * @author Srikanth Reddy Lingala
 *
 */
public class ExtractAllFiles {

    public ExtractAllFiles() {

        try {
            // Initiate ZipFile object with the path/name of the zip file.
            ZipFile zipFile = new ZipFile("c:\\ZipTest\\ExtractAllFiles.zip");

            // Extracts all files to the path specified
            zipFile.extractAll("c:\\ZipTest");

        } catch (ZipException e) {
            e.printStackTrace();
        }

    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        new ExtractAllFiles();
    }

}

关于java - 在java中提取ZIP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39673776/

相关文章:

servlets - Jetty http session 始终为 null(嵌入式容器、ServletHolder)

java - 如何使用zip4j和outputstream压缩文件夹和子文件夹

Zip4J 和 Zip Slip 漏洞

java - 如何编写classname.class能够返回对java.lang.Class对象的引用?

jsp - tomcat - 它们之前运行的类仍在内存中加载

Java 设计问题 : enum with underlying class

java - Head First servlet 示例不起作用

java - Zip4j 没有错误,尽管应该出现错误,但提取全部失败

java - 无法在Azure上设置hadoop中的映射器数量

java - C# 字符串/字符串 : Compare string like in Java (by Reference)