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. Linux中setup命令command not found如何解决?

    1.安装setuptool    yum -y install setuptool 2.系统服务管理  yum -y install ntsysv 3.setup中配套的防火墙设置也得装上去,不然会出 ...

  2. AP*更新供应商地点

    --更新供应商地点 PROCEDURE update_vendor_site(p_init_msg_list IN VARCHAR2 DEFAULT fnd_api.g_false, x_return ...

  3. jquery api 常见api 元素操作例子

    append_prepend.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> ...

  4. msado.tli

    // Created by Microsoft (R) C/C++ Compiler Version 10.00.40219.01 (d0b01b1b).//// e:\threadpool\mysq ...

  5. HDU 5186 zhx&#39;s submissions (进制转换)

    Problem Description As one of the most powerful brushes, zhx submits a lot of code on many oj and mo ...

  6. NHibernate中ISession的Flush

    不知道在执行Insert或者Delete,update之后为什么要调用Flush(),后来看了http://www.cnblogs.com/lyj/archive/2008/10/17/1313612 ...

  7. MySQL数据约束和关联查询

    1 默认值deafult:在建表的时候字段后使用 default ,默认值字段允许为null. 2 非空 not null:在建表的时候字段后使用  not null. 非空字段必须赋值,并且不能是n ...

  8. EasyUI combobox的panelHeight自动高度

    在使用EasyUI的时候,有时会用到combobox组件,这里的记录数不是很固定,设置为auto可能会被挡住,设置固定高度时,option很少时,也很丑 所以这里给出我自己自动调整combobox的p ...

  9. zeroclipboard解决跨域问题

    ZeroClipboard.setDefaults({ moviePath: "//d2glos6gx2bw40.cloudfront.net/C8QpR9/images/flash/Zer ...

  10. mybatis的#和$的差别

    在项目中假设使用mybatis保存形如"1,2,3"这种字符串.你须要使用"#"号取值.假设使用$符号会报错, 假设是查询形如"id in (1,2, ...