首页
学习
活动
专区
圈层
工具
发布

Java工具集-ZIP解压工具

  1. 添加依赖
代码语言:javascript
代码运行次数:0
复制
		<!--ZIP工具-->
        <dependency>
            <groupId>net.lingala.zip4j</groupId>
            <artifactId>zip4j</artifactId>
            <version>1.3.1</version>
        </dependency>
  1. 代码示例
代码语言:javascript
代码运行次数:0
复制
package com.simple.util.base.extend.zip;

import net.lingala.zip4j.core.ZipFile;

/**
 * @program: simple_tools
 * @description: ZIP解壓工具
 * @author: ChenWenLong
 * @create: 2020-01-07 16:52
 **/
public class ZipUtil {

    /**
     * 功能描述:
     * 〈解压zip文件〉
     *
     * @params : [zipFilePath, targetPath]
     * @return : void
     * @author : cwl
     * @date : 2020/1/7 16:52
     */
    public static void unzip(String zipFilePath,String targetPath) throws Exception{
        ZipFile zipFile = new ZipFile(zipFilePath);
        zipFile.extractAll(targetPath);
    }

    /**
     * 功能描述:
     * 〈解压zip文件(带密码)〉
     *
     * @params : [zipFilePath, password, targetPath]
     * @return : void
     * @author : cwl
     * @date : 2020/1/7 16:54
     */
    public static void unzip(String zipFilePath,String password,String targetPath) throws Exception{
        ZipFile zipFile = new ZipFile(zipFilePath);
        if (zipFile.isEncrypted()) {
            zipFile.setPassword(password);
        }
        zipFile.extractAll(targetPath);
    }

}
举报
领券