pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>demo</groupId>
<artifactId>spring</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<sevenzipjbinding.version>9.20-2.00beta</sevenzipjbinding.version>
<commons.io.version>2.0.1</commons.io.version>
</properties>
<dependencies>
<dependency>
<groupId>net.sf.sevenzipjbinding</groupId>
<artifactId>sevenzipjbinding</artifactId>
<version>${sevenzipjbinding.version}</version>
</dependency> <dependency>
<groupId>net.sf.sevenzipjbinding</groupId>
<artifactId>sevenzipjbinding-all-platforms</artifactId>
<version>${sevenzipjbinding.version}</version>
</dependency> <dependency>
<artifactId>commons-io</artifactId>
<groupId>commons-io</groupId>
<version>${commons.io.version}</version>
</dependency>
</dependencies> </project>
package urar;

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.io.IOUtils; import java.io.File;
import java.io.FileOutputStream;
import java.io.RandomAccessFile;
import java.util.Arrays; public class URaR {
/**
* @param file7zPath(7z文件路径)
* @param outPutPath(解压路径)
* @param passWord(文件密码.没有可随便写,或空)
* @return
* @throws Exception
* @Description (解压7z)
*/
public static int un7z(String file7zPath, final String outPutPath, String passWord) throws Exception {
IInArchive archive;
RandomAccessFile randomAccessFile;
randomAccessFile = new RandomAccessFile(file7zPath, "r");
archive = SevenZip.openInArchive(null, new RandomAccessFileInStream(randomAccessFile), passWord);
int numberOfItems = archive.getNumberOfItems();
ISimpleInArchive simpleInArchive = archive.getSimpleInterface();
for (final ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()) {
final int[] hash = new int[]{0};
if (!item.isFolder()) {
ExtractOperationResult result;
final long[] sizeArray = new long[1];
result = item.extractSlow(new ISequentialOutStream() {
public int write(byte[] data) throws SevenZipException {
try {
//判断压缩包内的文件是否存在
String parentFilePath = outPutPath + File.separator + item.getPath().substring(0, item.getPath().lastIndexOf(File.separator));
if (!new File(parentFilePath).exists()) {
new File(parentFilePath).mkdirs();
}
IOUtils.write(data, new FileOutputStream(new File(outPutPath + File.separator + item.getPath()), 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);
if (result == ExtractOperationResult.OK) {
System.out.println(String.format("%9X | %10s | %s", hash[0], sizeArray[0], item.getPath()));
} else {
System.out.printf("Error extracting item: " + result);
}
}
}
archive.close();
randomAccessFile.close(); return numberOfItems;
} public static void main(String[] args) throws Exception { un7z("C:\\Users\\spring\\Desktop\\A_(3169).rar", "d:\\111", "SPzfq");
}
}

解压

http://sevenzipjbind.sourceforge.net/compression_snippets.html

java 代码解压7z(带密码)转载请注明出处,谢谢的更多相关文章

  1. Java程序员面试宝典1 ---Java基础部分(该博文为原创,转载请注明出处)

    (该博文为原创,转载请注明出处   http://www.cnblogs.com/luyijoy/  by白手伊凡) 1.    基本概念 1)         Java为解释性语言,运行过程:程序源 ...

  2. 转载请注明出处: https://github.com/qiu-deqing/FE-interview

    转载请注明出处: https://github.com/qiu-deqing/FE-interview Table of Contents generated with DocToc FE-inter ...

  3. java代码解压zip文件

    import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.Inp ...

  4. linux rar 解压忽略带密码压缩包

    #解压忽略密码 rar x -p- file.rar #解压忽略子目录 rar x -ep file.rar

  5. 原创centos7安装hadoop2.7(转载请注明出处)

    启用ip vi /etc/sysconfig/network-scripts/ifcfg-ONBOOT=yes 编辑DNS /etc/resolv.conf nameserver 114.114.11 ...

  6. LAMP环境搭建 (原创帖,转载请注明出处)

    =============================说在前面的话==========================第一安装Mysql第二安装Apache-httpd第三安装PHP 第四配置PH ...

  7. Discuz的安装 (原创帖,转载请注明出处)

    ========================写在前面的话========================= 1.LAMP环境搭建请查看这篇日志:http://www.cnblogs.com/yic ...

  8. 移动端H5页面遇到的问题总结(转载请注明出处)

    最近刚做完一个移动端的项目,产品之无敌,过程之艰辛,我就不多说了,记录下在这个项目中遇到的问题,以防万一,虽然这些可能都是已经被N多前辈解决掉了的问题,也放在这里,算是为自己漫漫前端路铺了一颗小石子儿 ...

  9. zabbix的离线安装方法----孙祎晨,如需转载请注明出处,谢谢配合。

    ------------------------zabbix的离线安装步骤--------------------------------------------------------------- ...

随机推荐

  1. BZOJ 3489: A simple rmq problem

    3489: A simple rmq problem Time Limit: 40 Sec  Memory Limit: 600 MBSubmit: 1594  Solved: 520[Submit] ...

  2. 渗透测试-信息收集-c段收集

    平时做渗透测试我比较喜欢用lijiejie 写的 subDomainsBrute来爆破子域名 那么爆破完成后就想收集一下网站的c段信息 下面以平安为例 爆破得到子域名为 i.pingan.com.cn ...

  3. 测试开发面试-java持续累积

    接口和抽象类的区别 对java线程的理解 对java并发的理解 webservice的特点,用webservice的原因 守护线程和非守护线程 单例的实现,单例并发 如何实现定义一个类,只实现接口的任 ...

  4. 美国usan数据库——PDF提取

    QQ:231469242 原创 单个PDF内容提取 # -*- coding: utf-8 -*- """ io.open() is the preferred, hig ...

  5. Java学习笔记-Math类

    并非所有的类都需要main方法.Math类和JOptionPane类都没有main方法.这些类中所包含的方法主要是为了供其他类使用. package welcome; public class Tes ...

  6. Assetbundles

    Unity5.4 Assetbundles官方说明 http://iq007.blog.163.com/blog/static/265542019201681264813653?suggestedre ...

  7. java 多线程 1 线程 进程

    Java多线程(一).多线程的基本概念和使用 2012-09-10 16:06 5108人阅读 评论(0) 收藏 举报  分类: javaSE综合知识点(14)  版权声明:本文为博主原创文章,未经博 ...

  8. spring data jpa 调用存储过程

    网上这方面的例子不是很多,研究了一下,列出几个调用的方法. 假如我们有一个mysql的存储过程 CREATE DEFINER=`root`@`localhost` PROCEDURE `plus1in ...

  9. jetty9内嵌到应用,并在启动后加载WebApplicationInitializer,可运行jsp

    声明:本文所介绍的两功能都已经测试通过. 第一步先确保你用的是java 8,并依赖需要的相关jar包,以下是用gradle进行依赖的信息: ext { taglibsStandardVersion = ...

  10. 没有素描色彩基础适合学习UI吗,如果可以,该怎么学?

      文章背景,来自[ UI设计交流群 - 92588284 ]的一次探讨,由于个人视野有限,个中观点有失狭隘,仅供参考,欢迎拍砖: 问题一:一个朋友想学UI设计,没有任何基础的,也没有美术功底,想问问 ...