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系统默认情况下对这些文件的支持不是很好,如果直接用"归档管理器"打开会提示错误,因此今天跟大家分 ...
随机推荐
- yii2 用 bootstrap 给元素添加背景色
使用 bootstrap 给元素添加背景色 1.bootstrap 官网:http://getbootstrap.com/ 2.bootstrap 中文官网:http://v3.bootcss.com ...
- git使用,提交代码简记
强制覆盖本地修改:git reset --hard 项目初始时获取前端代码: git clone https://git.oschina.net/yudian/yudian-frontend.git ...
- js权威指南笔记
//如setTimeout的delay参数为0毫秒,那么指定的函数不会立即执行.只会把它放到队列中,等到前面处于等待状态的事件处理 //程序全部执行完成后,再调用它. function invoke( ...
- leetcode笔记--水箱问题
类型的引用:Solution *s=new Solution(); 1.Container With Most Water Given n non-negative integers a1, a2, ...
- 1、mysql初识
之前我们写代码需要存取信息时用的是文件可是用文件存取数据非常局限,今天我们将走进一个新的世界mysql 本片导航: 数据库由来 数据库概述 mysql介绍 下载安装 mysql软件基本管理 初识sql ...
- ssh远程登陆看不到用户名和主机名
使用secure crt远程登陆,发现看不到用户名和主机名,如下图所示 解决方法 sudo vim /etc/passwd root:x:::root:/root:/bin/bash sshd:x:: ...
- Brendan Gregg ----Linux Performance Tools NEWS
- Caused by: java.security.InvalidKeyException: Illegal key size or default parameters
How to remove the key size restriction in Java JDK? Are you developing your beautiful application us ...
- Go语言栈定义及相关方法实现
// stack 栈 package Algorithm import ( "errors" "reflect" ) // 栈定义 type Stack str ...
- vue项目启动时将localhost替换成指定ip地址
1.node启动vue项目时地址一般都是http://localhost:8080 2.config->index.js 中的host:‘localhost’换成host:‘你的本机ip’就可以 ...