安卓解压文件
Posted 呼啸
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了安卓解压文件相关的知识,希望对你有一定的参考价值。
主要就是采用流的方式处理大文件
1.先将源文件转换成安卓系统自带CheckedInputStream,这个是一个检验流:
CheckedInputStream cis = new CheckedInputStream(new FileInputStream(srcFile), new CRC32());
2.再将这个检验流转换成Zip输入流:
ZipInputStream zis = new ZipInputStream(cis);
3.获取zip流的实体:
while ((zipEntry = zis.getNextEntry()) != null)
4.然后用字节输出流的方式:
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFile));
int len;
byte[] buff = new byte[DEFAULT_BUFF_SIZE];
while ((len = zis.read(buff, 0 ,DEFAULT_BUFF_SIZE)) != -1)
bos.write(buff, 0, len);
完整代码:
public static File decompress(File srcFile, File destFile) throws Exception
while (destFile.exists())
destFile = new File(destFile.getAbsolutePath()+"1");
CheckedInputStream cis = new CheckedInputStream(new FileInputStream(srcFile), new CRC32());
ZipInputStream zis = new ZipInputStream(cis);
doDecompress(destFile, zis);
zis.close();
return destFile;
private static void doDecompress(File destFile, ZipInputStream zis) throws Exception
ZipEntry zipEntry = null;
while ((zipEntry = zis.getNextEntry()) != null)
String dir = destFile.getPath() + File.separator + zipEntry.getName();
File dirFile = new File(dir);
fileProber(dirFile);
if (zipEntry.isDirectory())
dirFile.mkdirs();
else
doDecompressFile(dirFile, zis);
zis.closeEntry();
private static void doDecompressFile(File destFile, ZipInputStream zis) throws Exception
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFile));
int len;
byte[] buff = new byte[DEFAULT_BUFF_SIZE];
while ((len = zis.read(buff, 0 ,DEFAULT_BUFF_SIZE)) != -1)
bos.write(buff, 0, len);
bos.close();
以上是关于安卓解压文件的主要内容,如果未能解决你的问题,请参考以下文章
安卓apk解压后得到的.so文件能直接放项目里面调用里面的方法吗?