android开发——解压缩zip文件

 

压缩文件在应用中的使用量也挺大的,就此写一下曾经在android中解压缩一个压缩文件的方法,

File zipFile = new File(FILE_PATH);//FILE_PATH为压缩文件的路径

ZipFile zf = new ZipFile(zipFile);

for(Enumeration<?> entries = zf.entries(); entries.hasMoreElements();){//遍历压缩文件中的所以文件

ZipEntry entry = ((ZipEntry)entries.nextElement());

InputStream is = zf.getInputStream(entry);

String str = sPath + File.separator + entry.getName();

str = new String(str.getBytes(“8859_1″),”GB2312″);//压缩文件的编码是8859_1,此处可将其转换成指定的编码

File desFile = new File(str);

if(!desFile.exists()){

File fileParentDir = desFile.getParentFile();

if(!fileParentDir.exists()){

fileParentDir.mkdirs();

}

desFile.createNewFile();

}

FileOutputStream out = new FileOutputStream(desFile);

byte buffer[] = new byte[1024*1024];

int readLength;

while((readLength = is.read(buffer)) > 0){

out.write(buffer, 0, readLength);

}

is.close();

out.close();

}

代码的内容很好理解,就是把压缩文件打开后依次以流的方式读取里面的内容并写入到指定文件中即可。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值