/** * * * 解壓工具類,耗時操做,應當放在異步線程中 */ public void getAnalysis(final String inUri, final String targUri, final int uncompressType) { try { /** * * 開始解壓 */ ZipInputStream Zin = new ZipInputStream(new FileInputStream(inUri));//輸入源zip路徑 BufferedInputStream Bin = new BufferedInputStream(Zin); String Parent = targUri; //輸出路徑(文件夾目錄) File Fout = null; ZipEntry entry; try { while ((entry = Zin.getNextEntry()) != null ) { String name=entry.getName(); /** * * 替換掉和系統不符合的目錄符號 */ if(name.contains("\\")){ name= name.replace("\\",File.separator); }else if(name.contains("/")){ name= name.replace("/",File.separator); } Fout = new File(targUri+File.separator+name); /** * 刪除舊的文件 */ if(Fout.exists()){ Fout.delete(); } File parent= Fout.getParentFile(); if(!parent.exists()){ parent.mkdirs(); } if( !entry.isDirectory()){ if(!Fout.exists()){ Fout.createNewFile(); } FileOutputStream out = new FileOutputStream(Fout); BufferedOutputStream Bout = new BufferedOutputStream(out); int b; while ((b = Bin.read()) != -1) { Bout.write(b); } Bout.flush(); Bout.close(); out.close(); System.out.println(Fout + "解壓成功"); }else { Fout.mkdirs(); continue; } } Bin.close(); Zin.close(); /** * 解壓完畢 * 提醒下一步 * * */ chioceMetch(uncompressType);// 這一步和解壓物關,不用的能夠刪除 } catch (FileNotFoundException e) { e.printStackTrace(); } } catch (IOException e) { Log.e("test",e.toString()); } }