public class ZipUtil {
public ZipUtil(){ } /**
* DeCompress the ZIP to the path
* @param zipFileString name of ZIP
* @param outPathString path to be unZIP
* @throws Exception
*/
public static void UnZipFolder(String zipFileString, String outPathString) throws Exception {
ZipInputStream inZip = new ZipInputStream(new FileInputStream(zipFileString));
ZipEntry zipEntry;
String szName = "";
System.out.println("start");
while ((zipEntry = inZip.getNextEntry()) != null) { szName = zipEntry.getName();
System.out.println(szName);
if (zipEntry.isDirectory()) {
// get the folder name of the widget
szName = szName.substring(0, szName.length() - 1);
File folder = new File(outPathString + File.separator + szName);
folder.mkdirs();
} else { File file = new File(outPathString + File.separator + szName);
file.createNewFile();
// get the output stream of the file
FileOutputStream out = new FileOutputStream(file);
int len;
byte[] buffer = new byte[1024];
// read (len) bytes into buffer
while ((len = inZip.read(buffer)) != -1) {
// write (len) byte from buffer at the position 0
out.write(buffer, 0, len);
out.flush();
}
out.close();
}
}
System.out.println("ssssss");
inZip.close();
} /**
* Compress file and folder
* @param srcFileString file or folder to be Compress
* @param zipFileString the path name of result ZIP
* @throws Exception
*/
public static void ZipFolder(String srcFileString, String zipFileString)throws Exception {
//create ZIP
ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(zipFileString));
//create the file
File file = new File(srcFileString);
//compress
ZipFiles(file.getParent()+File.separator, file.getName(), outZip);
//finish and close
outZip.finish();
outZip.close();
} /**
* compress files
* @param folderString
* @param fileString
* @param zipOutputSteam
* @throws Exception
*/
private static void ZipFiles(String folderString, String fileString, ZipOutputStream zipOutputSteam)throws Exception{
if(zipOutputSteam == null)
return;
File file = new File(folderString+fileString);
if (file.isFile()) {
ZipEntry zipEntry = new ZipEntry(fileString);
FileInputStream inputStream = new FileInputStream(file);
zipOutputSteam.putNextEntry(zipEntry);
int len;
byte[] buffer = new byte[4096];
while((len=inputStream.read(buffer)) != -1)
{
zipOutputSteam.write(buffer, 0, len);
}
zipOutputSteam.closeEntry();
}
else {
//folder
String fileList[] = file.list();
//no child file and compress
if (fileList.length <= 0) {
ZipEntry zipEntry = new ZipEntry(fileString+File.separator);
zipOutputSteam.putNextEntry(zipEntry);
zipOutputSteam.closeEntry();
}
//child files and recursion
for (int i = 0; i < fileList.length; i++) {
ZipFiles(folderString, fileString+java.io.File.separator+fileList[i], zipOutputSteam);
}//end of for
}
} /**
* return the InputStream of file in the ZIP
* @param zipFileString name of ZIP
* @param fileString name of file in the ZIP
* @return InputStream
* @throws Exception
*/
public static InputStream UpZip(String zipFileString, String fileString)throws Exception {
ZipFile zipFile = new ZipFile(zipFileString);
ZipEntry zipEntry = zipFile.getEntry(fileString);
return zipFile.getInputStream(zipEntry);
} /**
* return files list(file and folder) in the ZIP
* @param zipFileString ZIP name
* @param bContainFolder contain folder or not
* @param bContainFile contain file or not
* @return
* @throws Exception
*/
public static List<File> GetFileList(String zipFileString, boolean bContainFolder, boolean bContainFile)throws Exception {
List<File> fileList = new ArrayList<File>();
ZipInputStream inZip = new ZipInputStream(new FileInputStream(zipFileString));
ZipEntry zipEntry;
String szName = "";
while ((zipEntry = inZip.getNextEntry()) != null) {
szName = zipEntry.getName();
if (zipEntry.isDirectory()) {
// get the folder name of the widget
szName = szName.substring(0, szName.length() - 1);
File folder = new File(szName);
if (bContainFolder) {
fileList.add(folder);
} } else {
File file = new File(szName);
if (bContainFile) {
fileList.add(file);
}
}
}
inZip.close();
return fileList;
}
}

Android_Zip解压缩工具的更多相关文章

  1. Linux 下最为人熟知的解压缩工具

    很多时候,通过互联网发送或接收大文件和图片是一件令人头疼的事.压缩及解压缩工具正好可以应对这个问题.下面让我们快速浏览一些可以使得我们的工作更加轻松的开源工具. Tar Tar 由 ‘Tape arc ...

  2. GZIP压缩、解压缩工具类

    GZIP压缩.解压缩工具类: public class GZIPUtiles { public static String compress(String str) throws IOExceptio ...

  3. linux下归档、解压缩工具:tar命令

    tar是一个类似于windows下的解压缩工具,可以将一大堆文件或目录打包成一个文件,还可以通过特定选项使用压缩工具进行解压缩. 语法: tar (选项) (参数) 常用选项: -c:创建打包文件. ...

  4. Archiver 3 for Mac(解压缩工具) ,想压缩解压慢一点就这么难!

    Archiver 3 for Mac是一款分割合并解压缩工具,简单实用且功能齐全,你只需简单的拖放文件就可以进行压缩,还可以设定解压密码,从而保护自己的隐私.如果文件很大你还可以切割文件.Archiv ...

  5. ZIP解压缩工具类

    import java.io.File; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Expan ...

  6. zip压缩工具,unzip解压缩工具

    zip压缩工具,unzip解压缩工具=================== [root@aminglinux tmp]# yum install -y zip[root@aminglinux tmp] ...

  7. Linux操作系统的压缩、解压缩工具介绍

    Linux操作系统的压缩.解压缩工具介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.compress/uncompress命令常用参数 Linux compress命令: ...

  8. 【Linux_Fedora_应用系列】_5_如何安装XZ Utils 解压缩工具以及利用 xz工具来解压缩.xz文件

    有段时间没有来园子了,今天从 www.kernel.org 上面下载了一个 2.6.32.2 内核压缩包,下载 下来后发现是一个  .xz  结尾的文件,一看与通常的  .gz..bz2等格式不一样, ...

  9. RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2 新增解压缩工具类ZipHelper

    在项目对文件进行解压缩是非常常用的功能,对文件进行压缩存储或传输可以节省流量与空间.压缩文件的格式与方法都比较多,比较常用的国际标准是zip格式.压缩与解压缩的方法也很多,在.NET 2.0开始,在S ...

随机推荐

  1. 算法笔记_016:凸包问题(Java)

    目录 1 问题描述 2 解决方案 2.1 蛮力法 1 问题描述 给定一个平面上n个点的集合,它的凸包就是包含所有这些点的最小凸多边形,求取满足此条件的所有点. 另外,形象生动的描述: (1)我们可以把 ...

  2. Native App、Web App 还是Hybrid App

    Native App.Web App 还是Hybrid App? 技术 标点符 1年前 (2014-05-09) 3036℃ 0评论 一.什么是Native App? Native App即原生应用, ...

  3. Linux ext2/ext3文件系统详解

    转载: Linux ext2/ext3文件系统使用索引节点来记录文件信息,作用像windows的文件分配表.索引节点是一个结构,它包含了一个文件的长度.创建及修改时间.权限.所属关系.磁盘中的位置等信 ...

  4. 【转帖】阿里金融云:分布式服务注册中心(DSR)

    https://www.cloud.alipay.com/docs/middleware/register/index.html 分布式服务注册中心(DSR) 分布式服务注册中心简介 服务注册中心 ( ...

  5. T-sql 根据日期时间 按年份、月份、天来统计

    看统计结果: 这里利用的是convert函数,这里不得不说一下convert函数 CONVERT() 函数是把日期转换为新数据类型的通用函数. CONVERT() 函数可以用不同的格式显示日期/时间数 ...

  6. C# 编写Windows服务在VS中调试的步骤

    1.以管理员身份运行cmd 2.安装windows服务 cd C:\Windows\Microsoft.NET\Framework\v4.0.30319(InstallUtil.exe的路径,注意In ...

  7. HDU 1823 Luck and Love 二维线段树(树套树)

    点击打开链接 Luck and Love Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. SQLyog之MySQL客户端的下载、安装和使用(企业版)(破解)

    本博文的主要内容有 .SQLyog的下载 .SQLyog的安装 .SQLyog的使用 1.SQLyog_Enterprise的下载 比如,我这里,是放在D:\SoftWare 继续

  9. JavaScript之Web通讯

    web通信,一个特别大的topic,涉及面也是很广的.因最近学习了 javascript 中一些 web 通信知识,在这里总结下.文中应该会有理解错误或者表述不清晰的地方,还望斧正! 一.前言 1. ...

  10. atitit. 研发管理---如何根据自己的特挑选 产业、行业、职业、岗位与自己发展的关系

    atitit. 研发管理---如何根据自己的特挑选 产业.行业.职业.岗位与自己发展的关系 1. 产业及分类 1 2. 二.行业 2 3. 职业概念- 3 4. 职业划分 3 5. 职业兴趣分类 4 ...