各位,
我正在使用 zip4j API 在 java 中提取 .zip 文件,并且能够提取文件
我曾经使用压缩完整的目录来制作 zip,它包含文件和嵌套目录,使用
zipFile.addFolder(fileDirectory,parameters);//ZIP目录文件/文件夹
使用提取 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/