ZipUtils-压缩工具类
2015-08-10 11:42
387 查看
ZipUtils-压缩工具类
支持中文的解压工具类。更新于:2015-08-10
[code]import org.apache.tools.zip.ZipEntry; import org.apache.tools.zip.ZipFile; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Enumeration; public class ZipUtils { /** * 解压zip包,支持中文。 * 需要ant.jar包,下载地址:http://download.csdn.net/detail/qiantujava/8984345 * * @param zipFile 需要解压的文件,如:/mnt/sdcard/abc/abc.zip * @param zipFileDir 需要解压的文件所在的文件夹,如:/mnt/sdcard/abc/ * @throws IOException */ public static void unZipFile(String zipFile, String zipFileDir) throws IOException { BufferedInputStream bi; ZipFile zf = new ZipFile(zipFile, "GBK"); Enumeration e = zf.getEntries(); while (e.hasMoreElements()) { ZipEntry entry = (ZipEntry) e.nextElement(); String entryName = entry.getName(); String path = zipFileDir + "/" + entryName; if (entry.isDirectory()) { File dir = new File(path); if (!dir.exists()) dir.mkdirs(); } else { String fileDir = path.substring(0, path.lastIndexOf("/")); File fileDirFile = new File(fileDir); if (!fileDirFile.exists()) fileDirFile.mkdirs(); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(zipFileDir + "/" + entryName)); bi = new BufferedInputStream(zf.getInputStream(entry)); byte[] readContent = new byte[1024]; int readCount = bi.read(readContent); while (readCount != -1) { bos.write(readContent, 0, readCount); readCount = bi.read(readContent); } bos.close(); } } zf.close(); } }
相关文章推荐
- 【HDU35350】【Bomb】
- NTOJ-14-会场安排问题(贪心算法)
- java程序的换行符/n怎么写?
- Trace Logging Level
- 在Java中“\t”与空格的区别及其意义
- Django访问量和页面点击数统计
- javaScript改变HTML中的图片元素
- 判断对称矩阵
- HDOJ 2104 hide handkerchief(判断互质)
- [学习笔记]Lingo超经典案例大全
- 【OSS】Object复制
- Django访问量和页面点击数统计
- STM32学习笔记(六) SysTick系统时钟滴答实验(stm32中断入门)
- android ListView内数据的动态添加与删除
- IOS获取各种文件目录路径的方法
- 数据库三大范式
- 实现对话框的小三角
- 解读PHP中的垃圾回收机制
- 彻底理解C#中值类型和引用类型的区别
- hdoj.1296 Polynomial Problem【水题】 2015/08/10