java 代码解压7z(带密码)转载请注明出处,谢谢
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(带密码)转载请注明出处,谢谢的更多相关文章
- Java程序员面试宝典1 ---Java基础部分(该博文为原创,转载请注明出处)
(该博文为原创,转载请注明出处 http://www.cnblogs.com/luyijoy/ by白手伊凡) 1. 基本概念 1) Java为解释性语言,运行过程:程序源 ...
- 转载请注明出处: https://github.com/qiu-deqing/FE-interview
转载请注明出处: https://github.com/qiu-deqing/FE-interview Table of Contents generated with DocToc FE-inter ...
- java代码解压zip文件
import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.Inp ...
- linux rar 解压忽略带密码压缩包
#解压忽略密码 rar x -p- file.rar #解压忽略子目录 rar x -ep file.rar
- 原创centos7安装hadoop2.7(转载请注明出处)
启用ip vi /etc/sysconfig/network-scripts/ifcfg-ONBOOT=yes 编辑DNS /etc/resolv.conf nameserver 114.114.11 ...
- LAMP环境搭建 (原创帖,转载请注明出处)
=============================说在前面的话==========================第一安装Mysql第二安装Apache-httpd第三安装PHP 第四配置PH ...
- Discuz的安装 (原创帖,转载请注明出处)
========================写在前面的话========================= 1.LAMP环境搭建请查看这篇日志:http://www.cnblogs.com/yic ...
- 移动端H5页面遇到的问题总结(转载请注明出处)
最近刚做完一个移动端的项目,产品之无敌,过程之艰辛,我就不多说了,记录下在这个项目中遇到的问题,以防万一,虽然这些可能都是已经被N多前辈解决掉了的问题,也放在这里,算是为自己漫漫前端路铺了一颗小石子儿 ...
- zabbix的离线安装方法----孙祎晨,如需转载请注明出处,谢谢配合。
------------------------zabbix的离线安装步骤--------------------------------------------------------------- ...
随机推荐
- Codeforces 刷水记录
Codeforces-566F 题目大意:给出一个有序数列a,这个数列中每两个数,如果满足一个数能整除另一个数,则这两个数中间是有一条边的,现在有这样的图,求最大联通子图. 题解:并不需要把图搞出来, ...
- 解决ubuntu16.04软件中心闪退的问题
依次执行下列命令 sudo apt-get update sudo apt-get dist-upgrade sudo apt-get install --reinstall software-cen ...
- 为你的pip更换一个国内的镜像源
为你的pip更换一个国内的镜像源 是否常常为pypi官网被无故和谐掉导致pip不能下载python的各个包而痛心疾首? 是否常常在深夜里看着pip install 下载包的速度慢如乌龟而长吁短叹? 是 ...
- centos 单独安装apachebench
这两天在测试php性能优化方法. 为了做压力测试可观察效果,就选择了ApacheBench来作为压力测试工具.其实就是大家常说的ab. 但是这个工具是安装apache web server的时候自带的 ...
- throttle和debounce简单实现
function debounce(delay,fn){ var timer; return function(){ var ctx = this,args = arguments; clearTim ...
- PJAX的实现与应用
一.前言 web发展经历了一个漫长的周期,最开始很多人认为Javascript这们语言是前端开发的累赘,是个鸡肋,那个时候人们还享受着从一个a链接蹦 到另一个页面的web神奇魔术.后来随着JavaSc ...
- gvim 安装YCM
gvim的插件安装笔记 1.安装vunble插件 该插件主要用于管理别的插件,借助与git,从github来下载插件,实现自动安装前提条件是git安装正确,可以听过cnd使用,并且可以正确访问gith ...
- 数据量大的数据转换成jason并显示在页面上
代码列子: public ActionResult FindUserByUserId(SysMessageDTO model) { CustomResultMsg customResult = new ...
- [转]Oracle10g数据库自动诊断监视工具(ADDM)使用指南
第一章 ADDM简介 在Oracle9i及之前,DBA们已经拥有了很多很好用的性能分析工具,比如,tkprof.sql_trace.statspack.set even ...
- 【Android】Ignoring InnerClasses attribute for an anonymous inner class
这个问题是因为Android只能有6w个方法,解决方法,在defaultConfig中加入一句:multiDexEnabled true