Decompress a zip file using ZipFile : Zip Unzip « File « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » File » Zip Unzip 
11.59.2.Decompress a zip file using ZipFilePrevious/Next
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
  public static void main(String[] argsthrows Exception {
    String zipname = "data.zip";
    ZipFile zipFile = new ZipFile(zipname);
    Enumeration enumeration = zipFile.entries();
    while (enumeration.hasMoreElements()) {
      ZipEntry zipEntry = (ZipEntryenumeration.nextElement();
      System.out.println("Unzipping: " + zipEntry.getName());
      BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
      int size;
      byte[] buffer = new byte[2048];
      BufferedOutputStream bos = new BufferedOutputStream(
          new FileOutputStream(zipEntry.getName()), buffer.length);
      while ((size = bis.read(buffer, 0, buffer.length)) != -1) {
        bos.write(buffer, 0, size);
      }
      bos.flush();
      bos.close();
      bis.close();
    }
  }
}
11.59.Zip Unzip
11.59.1.Uses Zip compression to compress any number of files given on the command line
11.59.2.Decompress a zip file using ZipFile
11.59.3.Unzip
11.59.4.gzip
11.59.5.Compress a Byte Array
11.59.6.Decompress a Byte Array
11.59.7.Compress Java objects
11.59.8.Decompress Java objects
11.59.9.Compress string(byte array) by Deflater
11.59.10.Compare two zip files
11.59.11.Put file To Zip File
11.59.12.Unpack a segment from a zip
11.59.13.Unpack an archive from a URL
11.59.14.unzip File Into Directory
11.59.15.Zip a list of file into one zip file.
11.59.16.Zip up a directory
11.59.17.Zip files
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.