Android itself provides the decompression interface for the ZIP package
1 /**2 * Decompression Operation3 *4 * @paramzipfilestring The extracted file path Sdcard/0/a/b/test.zip5 * @paramoutpathstring Extract the destination path sdcard/0/a/b6 */7 Public Static voidUnzipfolder (String zipfilestring, String outpathstring) {8FileInputStream FIS =NULL;//File input stream9Zipinputstream Inzip =NULL;//zip package input stream provided by AndroidTen Try { OneFIS =NewFileInputStream (zipfilestring);//Read the file first, AInzip =NewZipinputstream (FIS);//convert a file stream into a zip input stream - ZipEntry zipentry;//zip entity -String szName = ""; the while((ZipEntry = Inzip.getnextentry ())! =NULL{//while (true) loop parsing -SzName =zipentry.getname (); - if(Zipentry.isdirectory ()) {//if it is a folder -SzName = szname.substring (0, Szname.length ()-1); +File folder =NewFile (outpathstring + file.separator +szName); - folder.mkdirs (); +}Else{//If the file AFile File =NewFile (outpathstring + file.separator +szName); at file.createnewfile (); -FileOutputStream out =Newfileoutputstream (file); - intlength; - byte[] buffer =New byte[1024]; - while(length = inzip.read (buffer))! =-1) { -Out.write (buffer, 0, length); in Out.flush (); - } to if(Out! =NULL) { + out.close (); - } the } * } $}Catch(FileNotFoundException e) {Panax Notoginseng e.printstacktrace (); -}Catch(IOException e) { the e.printstacktrace (); +}Catch(Exception e) { - e.printstacktrace (); -}finally { the if(FIS! =NULL) { - Try {Wuyi fis.close (); the}Catch(IOException e) { - e.printstacktrace (); Wu } - } About if(Inzip! =NULL) { $ Try { - inzip.close (); -}Catch(IOException e) { - e.printstacktrace (); A } + } the } - $}
Android Unzip the ZIP package implementation