Java Unzip zip file

Source: Internet
Author: User

Import Java.io.bufferedinputstream;import Java.io.bufferedoutputstream;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.zipexception;import Java.util.zip.zipfile;public class ZipUtil {        public static void Unzip (String zipfile) {//To unzip the file path to the filename "= ' new file ' (ZipFile);        if (!file.exists () | |!file.isfile ()) {return;        }//File current folder String BasePath = File.getparent ();        Buffer size int buffersize = 1024;        int count = 0;        Buffer byte[] buffer = new Byte[buffersize];            try {//zip file ZipFile zfile = new ZipFile (file);            Get all the elements in the zip package enumeration<zipentry> zips = (enumeration<zipentry>) zfile.entries (); Traverse all elements in the ZIP package while (zips.hasmoreelements ()) {//Get file ZipentRy entry = Zips.nextelement ();                File name String name = Entry.getname ();                The full path of the extracted file is String FilePath = basepath + file.separator + name;                    Handle the zip file containing the folder if (Entry.isdirectory ()) {System.out.println ("isdirectory");                    File path = new file (FilePath);                    if (!path.exists ()) {Path.mkdir ();                } continue;                }//Get compressed file input stream InputStream in = Zfile.getinputstream (entry);                Buffered input stream Bufferedinputstream bis = new Bufferedinputstream (in);                Buffered input stream Bufferedoutputstream bos = new Bufferedoutputstream (new FileOutputStream (FilePath)); Reads bytes from the input stream and writes to the output stream while (count = bis.read (buffer, 0, buffersize))! =-1) {Bos.wri                Te (buffer, 0, count);      }          Release resources Bos.flush ();                Bos.close ();                            Bos.close ();        }//Close file Zfile.close (); } catch (Zipexception e) {} catch (IOException e) {}} public static Voi    D main (string[] args) {ziputil.unzip ("E:\\pics.zip"); }}

Java Unzip zip file

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.