Unzip the local zip archive

Source: Internet
Author: User

Package Com.lapel.activity.html;import Java.io.file;import Java.io.fileoutputstream;import java.io.IOException; Import Java.io.inputstream;import java.util.enumeration;import Java.util.zip.zipentry;import java.util.zip.ZipFile  /** * * @author ding Unzip local compressed file * */public class Unziplocal {/** * * @param zipfilename * Compressed file path + filename + suffix * @param outputdirectory * After decompression path * @throws IOException */@SuppressWarnings ("unchecked") public static void unzip (String zipfilename, String outputdirectory) throws IOException {ZipFile ZipFile = null;try {zipfile = new ZipFile (ZipFile Name); Enumeration E = Zipfile.entries (); ZipEntry zipentry = null; File Dest = new file (outputdirectory);d est.mkdirs (); while (E.hasmoreelements ()) {ZipEntry = (zipentry) e.nextelement (); String entryName = Zipentry.getname (); InputStream in = null; FileOutputStream out = null;try {if (Zipentry.isdirectory ()) {String name = Zipentry.getname (); name = name.substring (0, NA Me.length ()-1); File F = new file (outputdiRectory + file.separator + name); F.mkdirs ();} else {int index = entryname.lastindexof ("\ \"), if (Index! =-1) {File DF = new file (outputdirectory + file.separator + entr Yname.substring (0, index));d f.mkdirs ();} index = Entryname.lastindexof ("/"); if (Index! =-1) {File DF = new file (outputdirectory + file.separator + entryname.subst Ring (0, index));d f.mkdirs ();} File F = new file (outputdirectory + file.separator + zipentry.getname ());//F.createnewfile (); in = Zipfile.getinputstream (zipentry); out = new FileOutputStream (f); int. c;byte[] by = new Byte[1024];while ((c = In.read (by))! =-1) {Out.write (by, 0 , c);} Out.flush ();}} catch (IOException ex) {ex.printstacktrace (); throw new IOException ("Decompression failed:" + ex.tostring ());} finally {if (in = null) {TR y {in.close ();} catch (IOException ex) {}}if (out! = null) {try {out.close ();} catch (IOException ex) {}}}} catch (Ioexce Ption ex) {ex.printstacktrace (); throw new IOException ("Decompression failed:" + ex.tostring ())} finally {if (ZipFile! = null) {try {ZIPFI Le.close ();} catch (IOException ex) {}}}} 

Unzip the local zip archive

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.