java解密zip文件(亲测可用)
之前我们写过java如何实现zip文件的解压,而有时,当我们的zip文件进行了加密(在我们知道秘钥的情况下),又想在查看的时候使用,故而需要使用解密
代码是从网上找的,没有做任何修改,测试了一下,不管是否安装压缩软件,密码是否含有中文,(windows下)都可以使用,需要的可以看一下,jar包可以在我的资源上下载一下,免费的,也是我从其他人那里花积分换的
public void unzipDirWithPassword( final String sourceZipFile ,final String destinationDir , final String password ){RandomAccessFile randomAccessFile = null;ISevenZipInArchive inArchive = null;try{randomAccessFile = new RandomAccessFile(sourceZipFile, "r");inArchive = SevenZip.openInArchive(null, // autodetect archive typenew RandomAccessFileInStream(randomAccessFile));// Getting simple interface of the archive inArchiveISimpleInArchive simpleInArchive = inArchive.getSimpleInterface();for (final ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()){final int[] hash = new int[] { 0 };if (!item.isFolder()){ExtractOperationResult result;result = item.extractSlow(new ISequentialOutStream(){public int write(final byte[] data) throws SevenZipException{try{if(item.getPath().indexOf(File.separator)>0){String path = destinationDir+File.separator+item.getPath(). substring(0,item.getPath().lastIndexOf(File.separator));File folderExisting = new File(path);if (!folderExisting.exists())new File(path).mkdirs();}if(!new File(destinationDir + File.separator+item.getPath()).exists()){new File(destinationDir).createNewFile();}OutputStream out = new FileOutputStream(destinationDir+ File.separator+item.getPath());out.write(data);out.close();}catch( Exception e ){e.printStackTrace();}hash[0] |= Arrays.hashCode(data);return data.length; // Return amount of proceed data}},password); /// password.if (result == ExtractOperationResult.OK){System.out.println(String.format("%9X | %s",hash[0], item.getPath()));}else{System.err.println("Error extracting item: " + result);}}}} catch (Exception e){e.printStackTrace();} finally {if (inArchive != null){try {inArchive.close();} catch (SevenZipException e){System.err.println("Error closing archive: " + e);e.printStackTrace();}}if (randomAccessFile != null) {try{randomAccessFile.close();} catch (IOException e){System.err.println("Error closing file: " + e);e.printStackTrace();}}}}
java解密zip文件(亲测可用)相关推荐
- PDF转word并去除水印以及处理的页数限制【pdf转word可编辑 百分百还原文件 亲测可用】
提示:操作aspose-pdf-22.10-jdk16.jar 对其重编译修改校验权限 使用javassist 重编译(学习测试使用,aspose所有的包都可以用该教程.亲自测试过的) 文章目录 前言 ...
- java ssm 项目案例,亲测可用的JAVA SSM项目
ta-INF\ 文件 39 2018-02-22 15:39 yosebook-ssm\WebContent\meta-INF\MANIFEST.MF 目录 ...
- 使用pdf.js展示pdf文件(亲测可用)
简单的实现方式 如果只是电脑端,可通过 iframe 标签嵌套预览 ios手机端可通过 a 标签包裹点击跳转预览(安卓端不行) 安卓电脑ios的通用方法 资料 老版本github地址 全版本地址 获取 ...
- ZIP RAR 压缩文件解密工具,亲测有效
ZIP-RAR文件解密工具,亲测有效 相信不少用户从网上下载的资源的时候遇到过加密的压缩ZIP.RAR文件,明明唾手可得的资源,但是却有密码,真是让人不开心,于是,我们便想方设法的破解这个压缩文件,但 ...
- java正则 括号_java正则表达式获取大括号小括号内容并判断数字和小数亲测可用...
获取大括号小括号内容 项目开发用到了,暂做个简单记录 private static String regex = "\\{([^}]*)\\}";//匹配大括号 private s ...
- Java正则获取小括号中的内容_java正则表达式获取大括号小括号内容并判断数字和小数亲测可用...
获取大括号小括号内容 项目开发用到了,暂做个简单记录 private static String regex = "\\{([^}]*)\\}";//匹配大括号 private s ...
- YDOOK: Sanic: Python request post请求 上传照片或文件 详细具体步骤 亲测可用!
YDOOK: Sanic: Python request post请求 上传照片或文件 详细具体步骤 亲测可用! ©YDOOK JYLin 1. 项目目录架构: Upload result: 上传结果 ...
- 微信支付rootca.pem通用根证书文件,亲测可用
微信支付rootca.pem通用根证书文件,2018年5月后微信支付默认不提供. 我当初找了好久又花钱又费时才找的可以用的证书,亲测可用. 链接:https://download.csdn.net/d ...
- 微信小程序码的生成(JAVA完整版) 亲测可用
JAVA生成小程序码(太阳码) 首先准备工具类,这里我使用的是QrUtil;废话不多说,上工具类; 工具类是获取token使用; appid = 小程序appID secret = 小程序秘钥 /** ...
最新文章
- 昨天下午面了个哥们,也就问了4个问题,但好像他被我虐了
- ios5 ARC机制介绍和使用
- qt 回调函数设置界面_回调函数实现类似QT中信号机制(最简单)
- 【Python】字典(Dictionary) items()方法
- 台式电脑不拉网线上网_技巧知识:电脑不用网线也可以上网了,你知道吗?
- 【原】webpack--文件监听的原理
- 【学习笔记】MOOC 数学文化赏析 笔记【补档】
- SSH-远程登录协议
- matlab连通域分割_MATLAB车牌识别之7个字符切割浅谈【抽丝剥茧】
- Error mounting /dev/sdc1 at /media/XXXX: Command-line `mount -t “ntfs“ -o
- 胡萝卜,是鸡蛋,还是咖啡豆
- 银河麒麟V10共享文件夹内无法创建wps文件的解决方法
- 界面开发控件DotNetBar for WPF教程:MobileRibbon快速入门指南
- C#进行注册表项和键值操作
- TranslateAnimation 使用详解
- 抖音小程序开发教程之初识抖音小程序 (教程含源码)
- HALCON学习论坛
- 东梓关富春江畔有感 文/江湖一劍客
- ncbi查找目的基因序列_如何查找目标基因序列?掌握这几招就够了!(NCBI篇)...
- 软件工程毕业设计课题(44)微信小程序毕业设计JAVA医院预约挂号小程序系统毕设作品项目