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. Redis源代码剖析和凝视(八)--- 对象系统(redisObject)

    Redis 对象系统 1. 介绍 redis中基于双端链表.简单动态字符串(sds).字典.跳跃表.整数集合.压缩列表.高速列表等等数据结构实现了一个对象系统,而且实现了5种不同的对象,每种对象都使用 ...

  2. shell学习三十二天----read读取一行

    标准输入输出与标准错误输出 标准输入/输出可能是软件工具设计原则里最主要的观念了.他的构想是:程序应有一个数据来源,数据出口(数据要去哪里),以及报告问题的地方.他们分别叫做标准输入,标准输出和标准错 ...

  3. js 多级联动(省、市、区)

      js 多级联动(省.市.区) CreateTime--2018年4月9日17:10:38 Author:Marydon 方式一: 数据从数据库获取,ajax实现局部刷新 方式二: 数据从json文 ...

  4. 〖Android〗/system/etc/fallback_fonts.xml

    <?xml version="1.0" encoding="utf-8"?> <!-- Fallback Fonts This file sp ...

  5. java反射--获取成员变量信息

    获取成员变量信息 代码及说明: public static void printFieldMessage(Object obj) { //要获取类的信息,首先要获取类的类类型 Class c=obj. ...

  6. javascript 原生实现 jquery live/delegate

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  7. hdu 4742 Pinball Game 3D(三维LIS&amp;cdq分治&amp;BIT维护最值)

    Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. Python-try except else finally有return时执行顺序探究

    学习python或者其他有异常控制的编程语 言, 大家很有可能说try except finally(try catch finally)的执行很简单,无非就是有异常的话执行except, final ...

  9. websphere设置jvm参数

    http://www.quiee.com.cn/archives/592/ websphere 选择服务器-> 应用程序服务器-> Server1-> 进程定义->Java 虚 ...

  10. Linux命令-文件搜索命令:which

    主要用途:查找linu命令,而不是磁盘上的普通文件,并且能看到命令的别名和目录. 区别whereis命令,which在path变量指定的目录中查找命令,并且返回第一个符合的结果.whereis是查找所 ...