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. Bzoj3450 Tyvj1952 Easy

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 570  Solved: 428[Submit][Status][Discuss] Descriptio ...

  2. nginx服务器http重定向到https的正确写法

    http重定向到https使用了nginx的重定向命令.那么应该如何写重定向?之前老版本的nginx可能使用了以下类似的格式. rewrite ^/(.*)$ http://domain.com/$1 ...

  3. dietpi请暂时不要升级为jessie

    关于升级到Debian最新稳定版jessie,作者是这样说的:一旦官方Raspbian升级到Jessie,DietPi也会随之切换到Jessie.由于改动较大,很多功能需要修改后才能正常使用,到时候可 ...

  4. maven报brors occurred during the build

    原因分析: 此问题一般发生在eclipse保存文件并自动部署时候.本人在写项目的时候,还没等部署好,关闭了了eclipse,结果出现了这种情况.有一种产生此错误的原因是因为此项目不不是由eclipse ...

  5. bootstrap学习笔记--bootstrap排版类的使用

    标题 Bootstrap 中定义了所有的 HTML 标题(h1 到 h6)的样式,这个和一般的html没啥区别.请看下面的实例: <h1>测试1 h1</h1> <h2& ...

  6. mysql代码执行漏洞

    mysql  (5.7, 5.6, 和 5.5版本)的所有默认安装配置,包括最新的版本,攻击者可以远程和本地利用该漏洞.该漏洞需要认证访问MYSQL数据库(通过网络连接或者像phpMyAdmin的we ...

  7. MySQL性能优化:索引

    MySQL性能优化:索引 索引提供指向存储在表的指定列中的数据值的指针,然后根据您指定的排序顺序对这些指针排序.数据库使用索引以找到特定值,然后顺指针找到包含该值的行.这样可以使对应于表的SQL语句执 ...

  8. TCPIP、Http、Socket的协议~ 写得挺形象,赞

    这篇文章写得挺形象,对TCPIP.HTTP.Socket的作用有一个整体层次的理解. 转载文章内容如下: 网络由下往上分为物理层.数据链路层.网络层.传输层.会话层.表示层和应用层.   通过初步的了 ...

  9. Android广播接收器BroadcastRceiver

    一.使用BroadcastRceiver 1.创建BroadcastRceiver(MyRceiver),重写OnReceiver: public void onReceive(Context con ...

  10. 现代软件工程作业 github使用

    Github使用 版本库的创建与同步 第一步:创建远程版本库并同步到本地 创建远程版本库 在地址栏输入www.github.com 并sign in 进入到个人主页,如下图示: 创建远程版本库:点击N ...