1 /**2 * Unzip the file to the specified directory.3 * 4 * @paramUnzipfilename5 * files that need to be decompressed (with path)6 * @paramMdestpath7 * The path to be stored after decompression8 **/9 Public Static voidUnZip (String unzipfilename, String mdestpath) {Ten if(!mdestpath.endswith ("/")) { OneMdestpath = Mdestpath + "/"; A } -FileOutputStream fileout =NULL; -Zipinputstream Zipin =NULL; theZipEntry ZipEntry =NULL; -File File =NULL; - intReadedbytes = 0; - byteBuf[] =New byte[4096]; + Try { -Zipin =NewZipinputstream (NewBufferedinputstream ( + NewFileInputStream (Unzipfilename)); A while((ZipEntry = Zipin.getnextentry ())! =NULL) { atFile =NewFile (Mdestpath +zipentry.getname ()); - if(Zipentry.isdirectory ()) { - file.mkdirs (); -}Else { - //if the directory for the specified file does not exist, it is created. -File parent =file.getparentfile (); in if(!parent.exists ()) { - parent.mkdirs (); to } +Fileout =Newfileoutputstream (file); - while((Readedbytes = Zipin.read (buf)) > 0) { theFileout.write (buf, 0, readedbytes); * } $ fileout.close ();Panax Notoginseng } - zipin.closeentry (); the } +}Catch(IOException IoE) { A ioe.printstacktrace (); the + } -}
Android-zip Decompression Method