Android Unzip the ZIP package implementation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.