Java代码中解压RAR文件
- import java.io.File;
- import java.io.FileOutputStream;
- import de.innosystec.unrar.Archive;
- import de.innosystec.unrar.rarfile.FileHeader;
- public class UnRARTools {
- public void unrar(File sourceRar, File destDir) throws Exception {
- Archive archive = null;
- FileOutputStream fos = null;
- System.out.println("Starting...");
- try {
- archive = new Archive(sourceRar);
- FileHeader fh = archive.nextFileHeader();
- int count = 0;
- File destFileName = null;
- while (fh != null) {
- System.out.println((++count) + ") " + fh.getFileNameString());
- String compressFileName = fh.getFileNameString().trim();
- destFileName = new File(destDir.getAbsolutePath() + "/" + compressFileName);
- if (fh.isDirectory()) {
- if (!destFileName.exists()) {
- destFileName.mkdirs();
- }
- fh = archive.nextFileHeader();
- continue;
- }
- if (!destFileName.getParentFile().exists()) {
- destFileName.getParentFile().mkdirs();
- }
- fos = new FileOutputStream(destFileName);
- archive.extractFile(fh, fos);
- fos.close();
- fos = null;
- fh = archive.nextFileHeader();
- }
- archive.close();
- archive = null;
- System.out.println("Finished !");
- } catch (Exception e) {
- throw e;
- } finally {
- if (fos != null) {
- try {
- fos.close();
- fos = null;
- } catch (Exception e) {
- //ignore
- }
- }
- if (archive != null) {
- try {
- archive.close();
- archive = null;
- } catch (Exception e) {
- //ignore
- }
- }
- }
- }
- }
需要引用到以下两个lib.
java-unrar-0.5.jar
http://www.java2s.com/Code/JarDownload/java/java-unrar-0.5.jar.zip
apache-commons-logging.jar
http://www.java2s.com/Code/JarDownload/apache-commons/apache-commons-logging.jar.zip
Java代码中解压RAR文件的更多相关文章
- linux中解压rar文件
linux平台默认是不支持RAR文件的解压,需要安装linux版本的RAR压缩软件,下载地址为:http://www.rarlab.com/download.htm 下载之后进行解压之后,进入rar目 ...
- 如何在linux中解压.rar文件
在liunx下原本是不支持rar文件的,需要安装liunx下的winrar版本 步骤: 1.http://www.rarsoft.com/rar/rarlinux-4.0.1.tar.gz 从这个网址 ...
- CentOS解压rar文件
默认不能解压rar文件. 进官网下载:http://www.rarsoft.com/download.htm RAR 5.40 for Linux x64 安装: # tar -zxvf rarlin ...
- Linux解压rar文件
Linux解压rar文件(unrar安装和使用,分卷解压) windows平台很多压缩文档为rar文件,那么怎么做到Linux解压rar文件(unrar安装和使用)? 简单,centos5安装unra ...
- python循环解压rar文件
python循环解压rar文件 C:. │ main.py │ ├─1_STL_算法简介 │ STL_算法简介.rar │ └─2_STL_算法_填充新值 STL_算法_填充新值.rar 事情是这样的 ...
- ubuntu解压rar文件
一般通过默认安装的ubuntu是不能解压rar文件的,只有在安装了rar解压工具之后,才可以解压.其实在ubuntu下安装rar解压工具是非常简 单的,只需要两个步骤就可以迅速搞定. ubuntu 下 ...
- rar x 解压rar文件,提示permission denied
问题: 解压rar文件,提示
- java 提取(解压)rar文件中特定后缀的文件并保存到指定目录
内容简介 本文主要介绍使用junrar来提取rar压缩文件中特定后缀(如:png,jpg)的文件并保存到指定目录下. 支持v4及以下版本压缩文件,不支持v5及以上. 在rar文件上右键,查看属性,在压 ...
- 在Ubuntu系统中解压rar和zip文件的方法
大家在以前的windows系统中会存有很多rar和zip格式的压缩文件,Ubuntu系统默认情况下对这些文件的支持不是很好,如果直接用"归档管理器"打开会提示错误,因此今天跟大家分 ...
随机推荐
- js实现60s倒计时效果
适用于获取验证码等其他场景,下面代码直接粘贴句可以使用 // 60s获取验证码的js与html var timer = null; var count = 60; $('.box>button' ...
- jquery中遍历
1.jQuery--Dom遍历 1)jquery遍历---祖先元素 parents() 方法返回被选元素的所有祖先元素,它一路向上直到文档的根元素 (<html>).也可以使用可选参数来过 ...
- 小甲鱼Python第十四课后习题
字符串格式化符号含义 符 号 说 明 %c 格式化字符及其ASCII码[>>> '%c' %97 'a'] %s ...
- nested exception is java.lang.ClassNotFoundException
当出现nested exception is java.lang.ClassNotFoundException这个异常的时候,首先排查类是否存在.如果存在,是maven项目的话,clean.insta ...
- pygame-KidsCanCode系列jumpy-part5-屏幕滚动
接上回继续,方块不断向上跳动的过程中,从视觉上看,整个背景屏幕应该不断向下滚动,而且上方要不断出现新档板(否则就没办法继续向上跳了),这节我们将来实现这种效果,感觉好象很复杂,但实现起来其实很简单,只 ...
- VBA 判断一个TXT编码方式,再创建一个新的文件,复制数据进去
如题,先读取一个文本文件判断编码(Unicode ANSI),就这两种编码然后将txt导入到excel表中,最后处理完成,再创建一个相同编码,不同文件名的txt文件,把新数据放进去 Sub test ...
- fastjson序列化乱序问题
1.初始化为有序json对象 JSONObject jsonOrdered= new JSONObject(true); 2.将String对象转换过程中,不要调整顺序 JSONObject json ...
- 使用Canvas制作画图工具
前 言 JRedu canvas是HTML5中重要的元素之一,canvas元素使用JavaScript在网页上绘制图像,画布是一个矩形区域,我们可以控制其每一个元素,并且canvas拥有多种的绘 ...
- 使用idea创建web项目
一直使用的是eclipse,有一个项目开发用的是idea,我也尝试着熟悉一下idea,先来创建一个web项目吧 1.idea下载安装使用 官方下载地址:https://www.jetbrains.co ...
- python接口自动化测试(三)-requests.post()
上一节介绍了 requests.get() 方法的基本使用,本节介绍 requests.post() 方法的使用: 本文目录: 一.方法定义 二.post方法简单使用 1.带数据的post 2 ...