java中如何实现 zip rar 7z 压缩包解压

 更新时间:2023年07月15日 11:24:57   作者:彭先生吖  
这篇文章主要介绍了java中如何实现 zip rar 7z 压缩包解压问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

java zip rar 7z 压缩包解压

7z和rar需要引入maven依赖,zip使用java自带的

<!-- 7z解压依赖 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-compress</artifactId>
            <version>1.9</version>
        </dependency>
        <dependency>
            <groupId>org.tukaani</groupId>
            <artifactId>xz</artifactId>
            <version>1.5</version>
        </dependency>
      	<!-- rar解压依赖 -- >
        <dependency>
            <groupId>net.sf.sevenzipjbinding</groupId>
            <artifactId>sevenzipjbinding</artifactId>
            <version>16.02-2.01</version>
        </dependency>
        <dependency>
            <groupId>net.sf.sevenzipjbinding</groupId>
            <artifactId>sevenzipjbinding-all-platforms</artifactId>
            <version>16.02-2.01</version>
        </dependency>

编写解压util工具类

/**
 * 文件解压缩工具类
 */	
public class UnFileUtil {
	/**
	 * rar解压缩
	 * @param rarFile	rar文件的全路径
	 * @return  压缩包中所有的文件
	 */	
	@SuppressWarnings("resource")
	public static Map<String, String> unRar(String rarFile) {
		RandomAccessFile randomAccessFile = null;
		IInArchive archive = null;
		try {
			File f = new File(rarFile);
			randomAccessFile = new RandomAccessFile(f.getAbsolutePath(), "rw");
			archive = SevenZip.openInArchive(ArchiveFormat.RAR,
					new RandomAccessFileInStream(randomAccessFile));
			String outPath = f.getAbsolutePath().substring(0, f.getAbsolutePath().indexOf("."));
			File zdir = new File(outPath);
			if (zdir.isDirectory()) {
				zdir.delete();
			}
			zdir.mkdir();
			int[] in = new int[archive.getNumberOfItems()];
			for (int i = 0; i < in.length; i++) {
				in[i] = i;
			}
			archive.extract(in, false, new ExtractCallback(archive,zdir.getAbsolutePath() + "/"));
			//解压后获取压缩包下全部文件列表
			Map<String, String> zipFileMap = getFileNameList(outPath,"");
			return zipFileMap;
		} catch (FileNotFoundException | SevenZipException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				if(randomAccessFile != null) randomAccessFile.close();
				if(archive != null) archive.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
	/**
	 * 获取压缩包中的全部文件
	 * @param path	文件夹路径
	 * @childName   每一个文件的每一层的路径==D==区分层数
	 * @return  压缩包中所有的文件
	 */	
	private static Map<String, String> getFileNameList(String path, String childName) {
		System.out.println("path:" + path + "---childName:"+childName);
		Map<String, String> files = new HashMap<>();
		File file = new File(path); // 需要获取的文件的路径
		String[] fileNameLists = file.list(); // 存储文件名的String数组
		File[] filePathLists = file.listFiles(); // 存储文件路径的String数组
		for (int i = 0; i < filePathLists.length; i++) {
			if (filePathLists[i].isFile()) {
				files.put(fileNameLists[i] + "==D==" + childName, path + File.separator + filePathLists[i].getName());
			} else {
				files.putAll(getFileNameList(path + File.separator + filePathLists[i].getName(), childName + "&" + filePathLists[i].getName()));
			}
		}
		return files;
	}
	/**
	 * zip解压缩
	 * @param zipFilePath			zip文件的全路径
	 * @param unzipFilePath			解压后文件保存路径
	 * @param includeZipFileName	解压后文件是否包含压缩包文件名,true包含,false不包含
	 * @return 压缩包中所有的文件
	 */
	@SuppressWarnings("resource")
	public static Map<String, String> unZip(String zipFilePath, String unzipFilePath, boolean includeZipFileName) throws Exception{
		File zipFile = new File(zipFilePath);
		//如果包含压缩包文件名,则处理保存路径
		if(includeZipFileName){
			String fileName = zipFile.getName();
			if(StringUtils.isNotEmpty(fileName)){
				fileName = fileName.substring(0,fileName.lastIndexOf("."));
			}
			unzipFilePath = unzipFilePath + File.separator + fileName;
		}
		//判断保存路径是否存在,不存在则创建
		File unzipFileDir = new File(unzipFilePath);
		if(!unzipFileDir.exists() || !unzipFileDir.isDirectory()){
			unzipFileDir.mkdirs();
		}
		//开始解压
		ZipEntry entry = null;
		String entryFilePath = null, entryDirPath = "";
		File entryFile = null, entryDir = null;
		int index = 0, count = 0, bufferSize = 1024;
		byte[] buffer = new byte[bufferSize];
		BufferedInputStream bis = null;
		BufferedOutputStream bos = null;
		Charset gbk = Charset.forName("GBK");
		ZipFile zip = new ZipFile(zipFile, gbk);
		try {
			Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zip.entries();
			while (entries.hasMoreElements()) {
				entry = entries.nextElement();
				entryFilePath = unzipFilePath + File.separator + entry.getName();
				entryFilePath = entryFilePath.replace("/", File.separator);
				index = entryFilePath.lastIndexOf(File.separator);
				if (index != -1) {
					entryDirPath = entryFilePath.substring(0, index);
				}
				entryDir = new File(entryDirPath);
				if (!entryDir.exists() || !entryDir.isDirectory()) {
					entryDir.mkdirs();
				}
				entryFile = new File(entryFilePath);
				//判断当前文件父类路径是否存在,不存在则创建
				if(!entryFile.getParentFile().exists() || !entryFile.getParentFile().isDirectory()){
					entryFile.getParentFile().mkdirs();
				}
				//不是文件说明是文件夹创建即可,无需写入
				if(entryFile.isDirectory()){
					continue;
				}
				bos = new BufferedOutputStream(new FileOutputStream(entryFile));
				bis = new BufferedInputStream(zip.getInputStream(entry));
				while ((count = bis.read(buffer, 0, bufferSize)) != -1) {
					bos.write(buffer, 0, count);
				}
			}
		}catch (Exception e){
			e.printStackTrace();
		}finally {
			bos.flush();
			bos.close();
			bis.close();
			zip.close();
		}
		Map<String, String> resultMap = getFileNameList(unzipFilePath, "");
		return resultMap;
	}
	/**
	 * zip解压缩
	 * @param zipFilePath			zip文件的全路径
	 * @param includeZipFileName	解压后文件是否包含压缩包文件名,true包含,false不包含
	 * @return 压缩包中所有的文件
	 */
	@SuppressWarnings("resource")
	public static Map<String, String> unZip(String zipFilePath, boolean includeZipFileName) throws Exception{
		File zipFile = new File(zipFilePath);
		String unzipFilePath = zipFilePath.substring(0, zipFilePath.lastIndexOf(File.separator));
		//如果包含压缩包文件名,则处理保存路径
		if(includeZipFileName){
			String fileName = zipFile.getName();
			if(StringUtils.isNotEmpty(fileName)){
				fileName = fileName.substring(0,fileName.lastIndexOf("."));
			}
			unzipFilePath = unzipFilePath + File.separator + fileName;
		}
		//判断保存路径是否存在,不存在则创建
		File unzipFileDir = new File(unzipFilePath);
		if(!unzipFileDir.exists() || !unzipFileDir.isDirectory()){
			unzipFileDir.mkdirs();
		}
		//开始解压
		ZipEntry entry = null;
		String entryFilePath = null, entryDirPath = "";
		File entryFile = null, entryDir = null;
		int index = 0, count = 0, bufferSize = 1024;
		byte[] buffer = new byte[bufferSize];
		BufferedInputStream bis = null;
		BufferedOutputStream bos = null;
		Charset gbk = Charset.forName("GBK");
		ZipFile zip = new ZipFile(zipFile, gbk);
		try {
			Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zip.entries();
			while (entries.hasMoreElements()) {
				entry = entries.nextElement();
				entryFilePath = unzipFilePath + File.separator + entry.getName();
				entryFilePath = entryFilePath.replace("/", File.separator);
				index = entryFilePath.lastIndexOf(File.separator);
				if (index != -1) {
					entryDirPath = entryFilePath.substring(0, index);
				}
				entryDir = new File(entryDirPath);
				if (!entryDir.exists() || !entryDir.isDirectory()) {
					entryDir.mkdirs();
				}
				entryFile = new File(entryFilePath);
				//判断当前文件父类路径是否存在,不存在则创建
				if(!entryFile.getParentFile().exists() || !entryFile.getParentFile().isDirectory()){
					entryFile.getParentFile().mkdirs();
				}
				//不是文件说明是文件夹创建即可,无需写入
				if(entryFile.isDirectory()){
					continue;
				}
				bos = new BufferedOutputStream(new FileOutputStream(entryFile));
				bis = new BufferedInputStream(zip.getInputStream(entry));
				while ((count = bis.read(buffer, 0, bufferSize)) != -1) {
					bos.write(buffer, 0, count);
				}
				bos.flush();
				bos.close();
				bis.close();
			}
		}catch (Exception e){
			e.printStackTrace();
		}finally {
			zip.close();
		}
		Map<String, String> resultMap = getFileNameList(unzipFilePath, "");
		return resultMap;
	}
	/**
	 * 7z解压缩
	 * @param z7zFilePath	7z文件的全路径
	 * @return  压缩包中所有的文件
	 */
	public static Map<String, String> un7z(String z7zFilePath){
		String un7zFilePath = "";		//压缩之后的绝对路径
		SevenZFile zIn = null;
		try {
			File file = new File(z7zFilePath);
			un7zFilePath = file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf(".7z"));
			zIn = new SevenZFile(file);
			SevenZArchiveEntry entry = null;
			File newFile = null;
			while ((entry = zIn.getNextEntry()) != null){
				//不是文件夹就进行解压
				if(!entry.isDirectory()){
					newFile = new File(un7zFilePath, entry.getName());
					if(!newFile.exists()){
						new File(newFile.getParent()).mkdirs();   //创建此文件的上层目录
					}
					OutputStream out = new FileOutputStream(newFile);
					BufferedOutputStream bos = new BufferedOutputStream(out);
					int len = -1;
					byte[] buf = new byte[(int)entry.getSize()];
					while ((len = zIn.read(buf)) != -1){
						bos.write(buf, 0, len);
					}
					bos.flush();
					bos.close();
					out.close();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try {
				if (zIn != null)
					zIn.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		Map<String, String> resultMap = getFileNameList(un7zFilePath, "");
		return resultMap;
	}
	public static void main(String[] args) {
		try {
			un7z("C:\\Users\\Admin\\Desktop\\1716F0190017.7z");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

java常见压缩包解压工具类(支持:zip、7z和rar)

pom依赖

        <groupId>org.apache.commons</groupId>
        <artifactId>commons-compress</artifactId>
        <version>1.9</version>
    </dependency>
    <dependency>
        <groupId>org.tukaani</groupId>
        <artifactId>xz</artifactId>
        <version>1.5</version>
    </dependency>
    <!-- rar解压依赖 -->
  <dependency>
      <groupId>net.sf.sevenzipjbinding</groupId>
      <artifactId>sevenzipjbinding</artifactId>
      <version>16.02-2.01</version>
  </dependency>
  <dependency>
      <groupId>net.sf.sevenzipjbinding</groupId>
      <artifactId>sevenzipjbinding-all-platforms</artifactId>
      <version>16.02-2.01</version>
  </dependency>

工具类实现

     
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.github.yulichang.common.support.func.S;
import com.onemap.business.web.resultsCheck.service.impl.ResultPackageReportServiceImpl;
import com.onemap.common.utils.StringUtils;
import net.sf.sevenzipjbinding.*;
import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream;
import net.sf.sevenzipjbinding.simple.ISimpleInArchive;
import net.sf.sevenzipjbinding.simple.ISimpleInArchiveItem;
import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
import org.apache.commons.compress.archivers.sevenz.SevenZFile;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.LongFunction;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/**
 * 文件解压缩工具类
 */
public class UnPagFileUtil {
    private static final Logger log = LoggerFactory.getLogger(UnFileUtil.class);
    /**
     * rar解压缩
     * @param rarFile    rar文件的全路径
     * @param outPath  解压路径
     * @return  压缩包中所有的文件
     */
    public static void unRarZip7Z(String rarFile, String outPath) throws Exception {
        if (rarFile.toLowerCase().endsWith(".zip")) {
            unZip(rarFile, outPath, false);
        } else if (rarFile.toLowerCase().endsWith(".rar")) {
            unRar(rarFile, outPath, "");
        } else if (rarFile.toLowerCase().endsWith(".7z")) {
            un7z(rarFile, outPath);
        }
    }
    /**
     * rar解压缩
     * @param rarFile    rar文件的全路径
     * @param outPath  解压路径
     * @return  压缩包中所有的文件
     */
    private static String unRar(String rarFile, String outPath, String passWord) {
        RandomAccessFile randomAccessFile = null;
        IInArchive inArchive = null;
        try {
            // 第一个参数是需要解压的压缩包路径,第二个参数参考JdkAPI文档的RandomAccessFile
            randomAccessFile = new RandomAccessFile(rarFile, "r");
            if (StringUtils.isNotBlank(passWord)) {
                inArchive = SevenZip.openInArchive(null, new RandomAccessFileInStream(randomAccessFile), passWord);
            } else {
                inArchive = SevenZip.openInArchive(null, new RandomAccessFileInStream(randomAccessFile));
            }
            ISimpleInArchive simpleInArchive = inArchive.getSimpleInterface();
            for (final ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()) {
                final int[] hash = new int[]{0};
                if (!item.isFolder()) {
                    ExtractOperationResult result;
                    final long[] sizeArray = new long[1];
                    File outFile = new File(outPath + File.separator+ item.getPath());
                    File parent = outFile.getParentFile();
                    if ((!parent.exists()) && (!parent.mkdirs())) {
                        continue;
                    }
                    if (StringUtils.isNotBlank(passWord)) {
                        result = item.extractSlow(data -> {
                            try {
                                IOUtils.write(data, new FileOutputStream(outFile, true));
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            hash[0] ^= Arrays.hashCode(data); // Consume data
                            sizeArray[0] += data.length;
                            return data.length; // Return amount of consumed
                        }, passWord);
                    } else {
                        result = item.extractSlow(data -> {
                            try {
                                IOUtils.write(data, new FileOutputStream(outFile, true));
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            hash[0] ^= Arrays.hashCode(data); // Consume data
                            sizeArray[0] += data.length;
                            return data.length; // Return amount of consumed
                        });
                    }
                    if (result == ExtractOperationResult.OK) {
                        log.error("解压rar成功...." + String.format("%9X | %10s | %s", hash[0], sizeArray[0], item.getPath()));
                    } else if (StringUtils.isNotBlank(passWord)) {
                        log.error("解压rar成功:密码错误或者其他错误...." + result);
                        return "password";
                    } else {
                        return "rar error";
                    }
                }
            }
        } catch (Exception e) {
            log.error("unRar error", e);
            return e.getMessage();
        } finally {
            try {
                inArchive.close();
                randomAccessFile.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return "";
    }
    /**
     * 获取压缩包中的全部文件
     * @param path    文件夹路径
     * @childName   每一个文件的每一层的路径==D==区分层数
     * @return  压缩包中所有的文件
     */
    private static Map<String, String> getFileNameList(String path, String childName) {
        System.out.println("path:" + path + "---childName:"+childName);
        Map<String, String> files = new HashMap<>();
        File file = new File(path); // 需要获取的文件的路径
        String[] fileNameLists = file.list(); // 存储文件名的String数组
        File[] filePathLists = file.listFiles(); // 存储文件路径的String数组
        for (int i = 0; i < filePathLists.length; i++) {
            if (filePathLists[i].isFile()) {
                files.put(fileNameLists[i] + "==D==" + childName, path + File.separator + filePathLists[i].getName());
            } else {
                files.putAll(getFileNameList(path + File.separator + filePathLists[i].getName(), childName + "&" + filePathLists[i].getName()));
            }
        }
        return files;
    }
    /**
     * zip解压缩
     * @param zipFilePath            zip文件的全路径
     * @param unzipFilePath            解压后文件保存路径
     * @param includeZipFileName    解压后文件是否包含压缩包文件名,true包含,false不包含
     * @return 压缩包中所有的文件
     */
    public static Map<String, String> unZip(String zipFilePath, String unzipFilePath, boolean includeZipFileName) throws Exception{
        File zipFile = new File(zipFilePath);
        //如果包含压缩包文件名,则处理保存路径
        if(includeZipFileName){
            String fileName = zipFile.getName();
            if(StringUtils.isNotEmpty(fileName)){
                fileName = fileName.substring(0,fileName.lastIndexOf("."));
            }
            unzipFilePath = unzipFilePath + File.separator + fileName;
        }
        //判断保存路径是否存在,不存在则创建
        File unzipFileDir = new File(unzipFilePath);
        if(!unzipFileDir.exists() || !unzipFileDir.isDirectory()){
            unzipFileDir.mkdirs();
        }
        //开始解压
        ZipEntry entry = null;
        String entryFilePath = null, entryDirPath = "";
        File entryFile = null, entryDir = null;
        int index = 0, count = 0, bufferSize = 1024;
        byte[] buffer = new byte[bufferSize];
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        Charset gbk = Charset.forName("GBK");
        ZipFile zip = new ZipFile(zipFile, gbk);
        try {
            Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zip.entries();
            while (entries.hasMoreElements()) {
                entry = entries.nextElement();
                entryFilePath = unzipFilePath + File.separator + entry.getName();
                entryFilePath = entryFilePath.replace("/", File.separator);
                index = entryFilePath.lastIndexOf(File.separator);
                if (index != -1) {
                    entryDirPath = entryFilePath.substring(0, index);
                }
                entryDir = new File(entryDirPath);
                if (!entryDir.exists() || !entryDir.isDirectory()) {
                    entryDir.mkdirs();
                }
                entryFile = new File(entryFilePath);
                //判断当前文件父类路径是否存在,不存在则创建
                if(!entryFile.getParentFile().exists() || !entryFile.getParentFile().isDirectory()){
                    entryFile.getParentFile().mkdirs();
                }
                //不是文件说明是文件夹创建即可,无需写入
                if(entryFile.isDirectory()){
                    continue;
                }
                bos = new BufferedOutputStream(new FileOutputStream(entryFile));
                bis = new BufferedInputStream(zip.getInputStream(entry));
                while ((count = bis.read(buffer, 0, bufferSize)) != -1) {
                    bos.write(buffer, 0, count);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            bos.flush();
            bos.close();
            bis.close();
            zip.close();
        }
        Map<String, String> resultMap = getFileNameList(unzipFilePath, "");
        return resultMap;
    }
    /**
     * zip解压缩
     * @param zipFilePath            zip文件的全路径
     * @param includeZipFileName    解压后文件是否包含压缩包文件名,true包含,false不包含
     * @return 压缩包中所有的文件
     */
    public static Map<String, String> unZip(String zipFilePath, boolean includeZipFileName) throws Exception{
        File zipFile = new File(zipFilePath);
        String unzipFilePath = zipFilePath.substring(0, zipFilePath.lastIndexOf(File.separator));
        //如果包含压缩包文件名,则处理保存路径
        if(includeZipFileName){
            String fileName = zipFile.getName();
            if(StringUtils.isNotEmpty(fileName)){
                fileName = fileName.substring(0,fileName.lastIndexOf("."));
            }
            unzipFilePath = unzipFilePath + File.separator + fileName;
        }
        //判断保存路径是否存在,不存在则创建
        File unzipFileDir = new File(unzipFilePath);
        if(!unzipFileDir.exists() || !unzipFileDir.isDirectory()){
            unzipFileDir.mkdirs();
        }
        //开始解压
        ZipEntry entry = null;
        String entryFilePath = null, entryDirPath = "";
        File entryFile = null, entryDir = null;
        int index = 0, count = 0, bufferSize = 1024;
        byte[] buffer = new byte[bufferSize];
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        Charset gbk = Charset.forName("GBK");
        ZipFile zip = new ZipFile(zipFile, gbk);
        try {
            Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zip.entries();
            while (entries.hasMoreElements()) {
                entry = entries.nextElement();
                entryFilePath = unzipFilePath + File.separator + entry.getName();
                entryFilePath = entryFilePath.replace("/", File.separator);
                index = entryFilePath.lastIndexOf(File.separator);
                if (index != -1) {
                    entryDirPath = entryFilePath.substring(0, index);
                }
                entryDir = new File(entryDirPath);
                if (!entryDir.exists() || !entryDir.isDirectory()) {
                    entryDir.mkdirs();
                }
                entryFile = new File(entryFilePath);
                //判断当前文件父类路径是否存在,不存在则创建
                if(!entryFile.getParentFile().exists() || !entryFile.getParentFile().isDirectory()){
                    entryFile.getParentFile().mkdirs();
                }
                //不是文件说明是文件夹创建即可,无需写入
                if(entryFile.isDirectory()){
                    continue;
                }
                bos = new BufferedOutputStream(new FileOutputStream(entryFile));
                bis = new BufferedInputStream(zip.getInputStream(entry));
                while ((count = bis.read(buffer, 0, bufferSize)) != -1) {
                    bos.write(buffer, 0, count);
                }
                bos.flush();
                bos.close();
                bis.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            zip.close();
        }
        Map<String, String> resultMap = getFileNameList(unzipFilePath, "");
        return resultMap;
    }
    /**
     * 7z解压缩
     * @param z7zFilePath    7z文件的全路径
     * @param outPath  解压路径
     * @return  压缩包中所有的文件
     */
    public static Map<String, String> un7z(String z7zFilePath, String outPath){
        SevenZFile zIn = null;
        try {
            File file = new File(z7zFilePath);
            zIn = new SevenZFile(file);
            SevenZArchiveEntry entry = null;
            File newFile = null;
            while ((entry = zIn.getNextEntry()) != null){
                //不是文件夹就进行解压
                if(!entry.isDirectory()){
                    newFile = new File(outPath, entry.getName());
                    if(!newFile.exists()){
                        new File(newFile.getParent()).mkdirs();   //创建此文件的上层目录
                    }
                    OutputStream out = new FileOutputStream(newFile);
                    BufferedOutputStream bos = new BufferedOutputStream(out);
                    int len = -1;
                    byte[] buf = new byte[(int)entry.getSize()];
                    while ((len = zIn.read(buf)) != -1){
                        bos.write(buf, 0, len);
                    }
                    bos.flush();
                    bos.close();
                    out.close();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                if (zIn != null) {
                    zIn.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        Map<String, String> resultMap = getFileNameList(outPath, "");
        return resultMap;
    }
    public static void main(String[] args) {
        try {
            String inputFile = "E:\\新建文件夹 (2)\\压缩测试.zip";
            String inputFile2 = "E:\\新建文件夹 (2)\\红光村批复.rar";
            String inputFile3 = "E:\\新建文件夹 (2)\\压缩测试.7z";
            String destDirPath = "E:\\新建文件夹\\zip";
            String destDirPath2 = "E:\\新建文件夹\\rar";
            String destDirPath3 = "E:\\新建文件夹\\7z";
            String suffix = inputFile.substring(inputFile.lastIndexOf("."));
            //File zipFile = new File("E:\\新建文件夹 (2)\\压缩测试.7z");
            //un7z(inputFile3, destDirPath3);
            //unZip(inputFile, destDirPath, false);
            unRar(inputFile2, destDirPath2, "");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • 导出maven项目依赖的jar包(图文教程)

    导出maven项目依赖的jar包(图文教程)

    下面小编就为大家带来一篇导出maven项目依赖的jar包(图文教程)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-10-10
  • 关于Mybatis-plus设置字段为空的正确写法

    关于Mybatis-plus设置字段为空的正确写法

    这篇文章主要介绍了关于Mybatis-plus设置字段为空的正确写法,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-07-07
  • Java日常练习题,每天进步一点点(63)

    Java日常练习题,每天进步一点点(63)

    下面小编就为大家带来一篇Java基础的几道练习题(分享)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧,希望可以帮到你
    2021-08-08
  • Java Socket实现传输压缩对象的方法示例

    Java Socket实现传输压缩对象的方法示例

    这篇文章主要介绍了Java Socket实现传输压缩对象的方法,结合具体实例形式分析了java socket针对数据的压缩、传输、接收、解压缩等操作相关实现技巧,需要的朋友可以参考下
    2017-06-06
  • 带你详细了解Java值传递和引用传递

    带你详细了解Java值传递和引用传递

    这篇文章主要介绍了带你详细了解Java值传递和引用传递,文中有非常详细的代码示例,对正在学习java的小伙伴们有一定的帮助,需要的朋友可以参考下
    2021-04-04
  • Windows中在IDEA上安装和使用JetBrains Mono字体的教程

    Windows中在IDEA上安装和使用JetBrains Mono字体的教程

    这篇文章主要介绍了Windows IDEA上安装和使用JetBrains Mono字体的教程,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-03-03
  • 快速掌握SpringBoot应用的启动入口

    快速掌握SpringBoot应用的启动入口

    本篇并不是深究内置服务器的启动过程,而是追溯Springboot启动之前到底做了什么?它是如何与我们经常写的@SpringBootApplication注解注释的main方法类绑定起来的?对SpringBoot启动入口相关知识感兴趣的朋友一起看看吧
    2022-05-05
  • SpringCloud HystrixDashboard服务监控详解

    SpringCloud HystrixDashboard服务监控详解

    Hystrix Dashboard 是Spring Cloud中查看Hystrix实例执行情况的一种仪表盘组件,支持查看单个实例和查看集群实例,本文将对其服务监控学习
    2022-11-11
  • JAVA IO API使用详解

    JAVA IO API使用详解

    本文通过理论、用法、实例详细说明了JAVA IO的使用,大家参考其中的实例代码实现自己的JAVA IO程序
    2013-11-11
  • java实现一个简单的网络爬虫代码示例

    java实现一个简单的网络爬虫代码示例

    这篇文章主要介绍了java实现一个简单的网络爬虫代码示例,还是挺不错的,这里分享给大家,需要的朋友可以参考下。
    2017-11-11

最新评论