1. 程式人生 > >Android 解壓zip檔案

Android 解壓zip檔案

這兩天研究了一下android下的解壓所技術,略有所獲,下面是解壓縮的操作方法。 private void unZipMapCache(){ try { InputStream is = this.getAssets().open(ASSETS_NAME); ZipInputStream zis= new ZipInputStream(is); ZipEntry entry = null; while((entry = zis.getNextEntry()) != null){ File file = new File("/mnt/sdcard/",entry.getName()); if(entry.isDirectory()){ file.mkdirs(); continue; }else{ file.createNewFile(); OutputStream myOutput = new FileOutputStream(file); byte[] buffer = new byte[1024]; int count; while ((count = zis.read(buffer)) != -1) { myOutput.write(buffer, 0, count); } myOutput.close(); } } zis.close(); is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }