/** * * * 解压工具类,耗时操做,应当放在异步线程中 */ 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()); } }