package com.ad.zip;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import android.os.Environment;
public class FileUtil {
public static final String SDCARD_PATH = Environment
.getExternalStorageDirectory() + "/";
public static final String CACHE_PATH_ROOT = SDCARD_PATH + "MBACache/images.zip";
public static final String SHUCHU_ROOT = SDCARD_PATH + "MBACache";
public static void zipMethod() {
long startTime=System.currentTimeMillis();
try {
ZipInputStream Zin=new ZipInputStream(new FileInputStream(CACHE_PATH_ROOT));//输入源zip路径
BufferedInputStream Bin=new BufferedInputStream(Zin);
String Parent=SHUCHU_ROOT; //输出路径(文件夹目录)
File Fout=null;
ZipEntry entry;
try {
// entry:images/menu_center.png entry.isDirectory():false
// fout:/mnt/sdcard/MBACache/images/menu_center.png
// Fout.getParent():/mnt/sdcard/MBACache/images
while((entry = Zin.getNextEntry())!=null && !entry.isDirectory()){
Fout=new File(Parent,entry.getName());
if(!Fout.exists()){
(new File(Fout.getParent())).mkdirs();
}
FileOutputStream out=new FileOutputStream(Fout);
BufferedOutputStream Bout=new BufferedOutputStream(out);
int b;
while((b=Bin.read())!=-1){
Bout.write(b);
}
Bout.close();
out.close();
System.out.println(Fout+"解压成功");
}
Bin.close();
Zin.close();
} catch (IOException e) {
System.out.println("e1---->"+e);
}
} catch (FileNotFoundException e) {
System.out.println("e2---->"+e);
}
long endTime=System.currentTimeMillis();
System.out.println("耗费时间: "+(endTime-startTime)+" ms");
}
}
分享到:
相关推荐
Android端zip压缩与解压,目前暂时只做zip格式支持,基于Zip4j (http://www.lingala.net/zip4j/)进行扩展成工具类,支持对单个文件,多个文件以及文件夹进行压缩,对压缩文件解压到到指定目录,支持压缩解压使用密码...
解压没问题,挺实用,最好跟打包zip一起看,有利于理解。
android 解压 ,内含zip4jjar包,支持加密解压,子线程解压handler发送解压进度给主线程,一个解压demo
android 下C写的一个解压Zip的小demo
android解压zip文件测试过可以用,只要改下参数就能使用了
android Zip解压、压缩 demo
在android开发中,有时候需要将文件打包成zip或将zip解压,如果直接用java.util.zip包下面的类会出现中文乱码,如果直接用org.apache.tools.zip(ant包中的压缩功能)会影响项目的编译时间; 故将ant包中文件瘦身,既...
Android Java zip 解压库,全部源代码,代码很精简,可以取到每个文件在压缩文件中的起始位置及大小信息。
android ZIP文件的解压,word文档详细解释zip文件的解压
android zip解压
Android中zip解压漏洞分析
Android 在线下载压缩包并解压到指定目录.zip
解压固定路径下的zip包输出里面文件的内容,并分别保存
Android端zip压缩与解压,目前暂时只做zip格式支持,基于Zip4j 进行扩展成工具类,支持对单个文件,多个文件以及文件夹进行压缩,对压缩文件解压到到指定目录,支持压缩解压使用密码。
Android代码实现zip文件的下载,下载完成后立即解压。
其实在网上有很多介绍下载文件或者解压zip文件的文章,但是两者结合的不多,所以这篇文章在此记录一下下载zip文件并直接解压的方法,直接上代码,文末有源码下载。 下载: import java.io.BufferedInputStream; ...
基于zip4j开源框架实现android解压带有密码的zip文件(进度条显示),项目中有jar包,非常好用。解压、压缩、压缩添加密码、解压带有密码的zip都可以使用。
自己编写的解压文件,可以用Java或者android上调用方法,用法已经写在文档里面
下面小编就为大家分享一篇Android 不解压直接读取zip包的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧