在Android的资产解压缩文件 [英] Unzip File in Android Assets

查看:138
本文介绍了在Android的资产解压缩文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把zip文件在Android资产。我如何提取在Android内部存储的文件?我知道如何得到的文件,但我不知道如何解压。这是我的code ..

I put a zip file in the android assets. How do i extract the file in the android internal storage? I know how to get the file, but i don't know how to extract it. This is my code..

的Util拉链;

邮编=新的Util();

zip.copyFileFromAsset(这一点,myfile.zip,getExternalStorage()+ /安卓/数据/ edu.binus.profile /);

感谢您的帮助:D

推荐答案

这一块code可以帮助你....只是擦肩而过,你要提取的文件保存到这个zip文件,并将该位置一流的同时使一个对象......并调用解压方法...

This piece of code will help you....Just pass the zipfile location and the location where you want the extracted files to be saved to this class while making an object...and call unzip method...

    public class Decompress { 
  private String zip; 
  private String loc; 

  public Decompress(String zipFile, String location) { 
    zip = zipFile; 
    loc = location; 

    dirChecker(""); 
  } 

  public void unzip() { 
    try  { 
      FileInputStream fin = new FileInputStream(zip); 
      ZipInputStream zin = new ZipInputStream(fin); 
      ZipEntry ze = null; 
      while ((ze = zin.getNextEntry()) != null) { 
        Log.v("Decompress", "Unzipping " + ze.getName()); 

        if(ze.isDirectory()) { 
          dirChecker(ze.getName()); 
        } else { 
          FileOutputStream fout = new FileOutputStream(loc + ze.getName()); 
          for (int c = zin.read(); c != -1; c = zin.read()) { 
            fout.write(c); 
          } 

          zin.closeEntry(); 
          fout.close(); 
        } 

      } 
      zin.close(); 
    } catch(Exception e) { 
      Log.e("Decompress", "unzip", e); 
    } 

  } 

  private void dirChecker(String dir) { 
    File f = new File(_location + dir); 

    if(!f.isDirectory()) { 
      f.mkdirs(); 
    } 
  } 
} 

这篇关于在Android的资产解压缩文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆