美文网首页
Android常用的压缩格式ZIP

Android常用的压缩格式ZIP

作者: 陈陈_04d0 | 来源:发表于2020-05-29 10:37 被阅读0次

安卓目前有两种解压zip 方法: ZipFile和ZipInputStream 为什么两种呢,让我们一起来了解一下吧

ZipInputStream

FileInputStream fis = new FileInputStream(files);

ZipInputStream zis = new ZipInputStream(newBufferedInputStream(fis));

byte[] buffer = new byte[8192];

while((ze=zis.getNextEntry())!=null){

File dstFile = newFile(dir+"/"+ze.getName());

FileOutputStream fos =new FileOutputStream(dstFile);

BufferedOutputStream fos = new BufferedOutputStream(dstFile);

while((count = zis.read(buffer))!= -1){

fos.write(buffer,0,count);

} }

ZipFile:

ZipFile zipFile = new ZipFile(files);

InputStream is = null;

Enumeration e = zipFile.entries();

while (e.hasMoreElements()) {

entry = (ZipEntry)e.nextElement();

is = new BufferedInputStream(zipFile.getInputStream(entry));

dstFile = newFile(dir+"/"+entry.getName());

fos = newFileOutputStream(dstFile);

byte[] buffer = newbyte[8192];

while( (count =is.read(buffer, 0, buffer.length)) != -1){

fos.write(buffer,0,count);

} }

结论:1,ZipFile的read调用的次数减少39%~93%,可以看出ZipFile的解压效率更高

            2,ZipFile解压文件耗时,相比ZipInputStream有22%到73%的减少

既然ZipFile更性能各方面领先,那么ZipInputStream有什么用呢,那我们结合场景来看看他们的优劣势,

1,如果ZIP文件已保存在磁盘,且解压ZIP中的所有文件,建议用ZipFile,效率较ZipInputStream有15%~27%的提升。

2,仅解压ZIP中间的某些文件,建议用ZipFile

3,如果ZIP没有在磁盘上或者顺序解压一小部分文件,又或ZIP文件目录遭到损坏(网络接收的数据,边接收边解压),建议用ZipInputStream

相关文章

  • 转载:Android 解压zip文件

    转自:Android 解压zip文件你知道多少? 对于Android 常用的压缩格式ZIP ,你了解多少? And...

  • 压缩命令 zip gz

    常用压缩格式: .zip .gz .bz2常用压缩格式: .tar.gz .tar.bz2 .zip格式...

  • 14 Linux压缩命令

    压缩与解压缩 常用压缩格式:.zip .gz .bz2常用压缩格式:.tar.gz .tar.bz2 .zip压缩...

  • Linux解压缩命令

    常用的压缩格式: .zip格式压缩:linux和windows中的zip格式可以通用 压缩文件夹: 解压缩: 删除...

  • 5.Linux—压缩命令

    压缩命令 压缩常用的是:.tar.gz .tar.zb2 常用压缩格式:.zip .gz .bz2 常用压缩...

  • Linux系统学习之压缩命令(6)

    Linux中常用压缩格式:.zip、.gz、.bz2、.tar.gz、.tar.bz2 .zip格式 注:压缩文件...

  • Android常用的压缩格式ZIP

    安卓目前有两种解压zip 方法:ZipFile和ZipInputStream 为什么两种呢,让我们一起来了解一下吧...

  • Linux压缩与解压缩命令

    常用压缩格式 压缩格式: .zip、.gz、.bz2、.tar.gz、.tar.bz2、.tar.xz最常用的是....

  • Linux 2018-10-20

    #压缩与打包命令 压缩最常用的是 : .tar.gz .tar.bz2 常用压缩格式:.zip .gz .bz...

  • day14 -文件压缩

    《 文件压缩 》zip压缩 格式 压缩工具 .zip ...

网友评论

      本文标题:Android常用的压缩格式ZIP

      本文链接:https://www.haomeiwen.com/subject/xcztzhtx.html