java zip文件的解压缩(支持中文文件名)
用的apache的ant包,下载导入即可。由于过程比较简单,直接上代码。
代码可直接复制使用。
如果想在android上使用,记得要在AndroidManifest.xml里添加权限:
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.zip.ZipException; import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile; /**
* 可以处理中文文件名
*/
public class jieya { public static void main(String[] args) { /**
* 解压文件
*/
File zipFile = new File("e:/压缩sdhjk.rar"); String path = "e:/zipfile/"; try { unZipFiles(zipFile, path); } catch (Exception e) { System.out.println("解压异常"); }
} /**
* 解压到指定目录
*
* @param zipPath
* @param descDir
* @author isea533
*/
public static void unZipFiles(String zipPath, String descDir) { try { unZipFiles(new File(zipPath), descDir); } catch (Exception e) { e.printStackTrace();
}
} /**
* 解压文件到指定目录
*
* @param zipFile
* @param descDir
* @author isea533
*/
@SuppressWarnings("rawtypes")
public static void unZipFiles(File zipFile, String descDir) { File pathFile = new File(descDir); if (!pathFile.exists()) { pathFile.mkdirs(); } try { ZipFile zip = new ZipFile(zipFile); for (Enumeration entries = zip.getEntries(); entries
.hasMoreElements();) { ZipEntry entry = (ZipEntry) entries.nextElement(); String zipEntryName = entry.getName(); InputStream in = zip.getInputStream(entry); String outPath = (descDir + zipEntryName)
.replaceAll("\\*", "/"); // 判断路径是否存在,不存在则创建文件路径
File file = new File(outPath.substring(0,
outPath.lastIndexOf('/'))); if (!file.exists()) { file.mkdirs(); } // 判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
if (new File(outPath).isDirectory()) { continue; }
// 输出文件路径信息
System.out.println(outPath); OutputStream out = new FileOutputStream(outPath); byte[] buf1 = new byte[1024]; int len; while ((len = in.read(buf1)) > 0) { out.write(buf1, 0, len); } in.close(); out.close(); }
} catch (ZipException e) { e.printStackTrace(); System.out.println("压缩文件打开异常"); } catch (FileNotFoundException e) { e.printStackTrace();
System.out.println("文件没有找到"); } catch (IOException e) { e.printStackTrace(); System.out.println("io异常");
} System.out.println("******************解压完毕********************");
} }
java zip文件的解压缩(支持中文文件名)的更多相关文章
- java Zip文件解压缩
java Zip文件解压缩 为了解压缩zip都折腾两天了,查看了许多谷歌.百度来的code, 真实无语了,绝大多数是不能用的.这可能跟我的开发环境有关吧. 我用的是Ubuntu14.04,eclips ...
- Servlet 下载文件及支持中文文件名
Sevlet 下载pdf文件 支持中文文件名 package html2pdf.controller; import java.io.File; import java.io.FileInputStr ...
- FullSync不支持中文文件名
FullSync,能实现多种方式.协议的目录同步软件,但不支持中文文件名.
- tomcat支持中文文件名下载
http://blog.csdn.net/wnczwl369/article/details/7483806 Tomcat 是Java开发者使用得较多的一个Web服务器,因为它占用资源小,运行速度快等 ...
- springmvc上传zip文件并解压缩代码示例
<input type="file" id="file" name="file"> spring中的配置: <!-- ...
- 让Tomcat支持中文文件名
--参考链接:http://blog.chinaunix.net/uid-26284395-id-3044132.html 解决问题的核心在于修改Tomcat的配置,在Server.xml文件中添加一 ...
- 使用Java对文件进行解压缩
最近在一个项目中需要对文件进行自动的解压缩,Java提供了这种支持,还是挺好用的. 工具包封装在java.util.zip中. 1.首先是多个文件压缩成一个ZIP文件 思路:用一个ZipOutputS ...
- koala编译scss文件时不支持中文字体的解决方案
第一种方案:在scss文件第一行加上这行代码@charset "utf-8"; 第二种方案: scss文件编译时候使用ruby环境,出现 Syntax error: Invalid ...
- 161012、JAVA读写文件,如何避免中文乱码
1.JAVA读取文件,避免中文乱码. /** * 读取文件内容 * * @param filePathAndName * String 如 c:\\1.txt 绝对路径 * @return boole ...
随机推荐
- WCF服务编程中使用SvcMap实现类型共享等技巧【转】
原文链接:http://www.cr173.com/html/19026_1.html 国外的一篇文章:Sharing DataContracts between WCF Services 文中提到的 ...
- 使用AIDL将接口暴露给客户端(远程绑定Service)
import java.util.Timer;import java.util.TimerTask; import jww.mediaprovidertest.ICat.Stub;import and ...
- android 计算器的实现(转)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- winform插入sql的事务处理
实现目的:点击按钮,原子性执行两条sql语句,同时成功或同时失败 数据库有这三个字段(忽略已有的一条记录): 一.用事务的sql语句 按钮事件完整代码: //事务处理插入sql语句 using (SQ ...
- Ibatis.Net 入门示例(一)
新项目用的是Ibatis.Net.哥的感觉是NHibernate才是哥的最爱.没办法,即使重复,也要抽时间学习.努力做好这份工作再说吧. 一.Ibatis.Net-SQLServer2008 还是以哥 ...
- 如何对Linux的grub进行加密
一.加密 设置grub密码: 众所周知,通过编辑GRUB启动参数可以轻松的进入单用户模式从而修改root密码,这对于一台多用户的计算机或服务器来说,无疑增加了安全隐患.大家一定很像为自己的GRUB加一 ...
- JS获取上传文件的名称、格式、大小
<input id="File1" type="file" onchange="checkFile(this)" /> 方式一) ...
- MongoDB应用篇(转)
一.高级查询 1. 查询操作符 1.1 比较操作符$gt,$lt,$gte,$lte 实例: select * from things where field<value -- 等价于db.th ...
- alpha,hidden,opaque的一些认识
如果opaque设置为YES,那么视图会被当做全视图来对待,系统会重绘整个视图 如果opaque设置为NO,那么系统会减少开销,以其中的内容来判定重绘的视图 如果把视图的背景色设置为透明那个,那么op ...
- (转)iOS应用程序生命周期(前后台切换,应用的各种状态)详解
原文:http://blog.csdn.net/totogo2010/article/details/8048652 iOS应用程序生命周期(前后台切换,应用的各种状态)详解 分类: ...