Decompress a zip file using ZipInputStream : Zip Tar File « File Input Output « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » File Input Output » Zip Tar FileScreenshots 
Decompress a zip file using ZipInputStream
       

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
  public static void main(String[] argsthrows Exception {
    String zipname = "data.zip";
    FileInputStream fis = new FileInputStream(zipname);
    ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
    ZipEntry entry;

    while ((entry = zis.getNextEntry()) != null) {
      System.out.println("Unzipping: " + entry.getName());

      int size;
      byte[] buffer = new byte[2048];

      FileOutputStream fos = new FileOutputStream(entry.getName());
      BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);

      while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
        bos.write(buffer, 0, size);
      }
      bos.flush();
      bos.close();
    }
    zis.close();
    fis.close();
  }
}
 

   
    
    
    
    
    
    
  
Related examples in the same category
1. Extract contents of a zip file
2. List the contents of a zip file
3. Read entries in a zip / compressed file
4. Decompress a zip file using ZipFile
5. Create checksum for a zip file
6. Read a zip file checksum value
7. Create a zip file with java.util.zip package
8. Extract file/files from a zip file
9. Read files within a zip file
10. Retrieve a compressed file from a ZIP file
11. Retrieve the contents of a ZIP file
12. Making a zip file of directory including its subdirectories recursively
13. Displaying contents of a compressed zip file
14. Compress a Byte Array
15. Decompress a Byte Array
16. Read zip file
17. Write Zip file
18. The java.util.zip package can be used to create a checksum.
19. Read the content of a zip file ZipFile
20. List the entries of a zip file
21. Compressing Streams: Zipper, Java example
22. Compressing Streams: Parity Checksum
23. Compressing Streams: File Summer
24. Create a simple ZIP File: not retain any directory path information about the files.
25. Decompress a ZIP file.
26. Decompressing a Byte Array
27. Zip unzip byte array
28. Creating a ZIP File
29. Listing the Contents of a ZIP File
30. Retrieving a Compressed File from a ZIP File
31. Calculating the Checksum of a Byte Array (Compute Adler-32 checksum)
32. Compute CRC-32 checksum
33. Calculating the Checksum of a File
34. Compress string(byte array) by Deflater
35. Use Java code to zip a folder
36. Uses Zip compression to compress any number of files given on the command line
37. Load zip file and scan zip file
38. Reading the Contents of a ZIP File
39. UnZip -- print or unzip a JAR or PKZIP file using java.util.zip
40. Tape Archive Lister: Tar file
41. Compressing a Byte Array
42. Tar file stream
43. Tar file and untar file
44. bzip source code
45. Unpack an archive from a URL
46. Compare two zip files
47. Determine whether a file is a ZIP File.
48. Zip up a directory
49. Check sum for a path
50. Check sum for an InputStream
51. Extract zip file to destination folder
52. Return the first directory of this archive. This is needed to determine the plugin directory
53. Makes a zip file named xmlFileName from xmlURL at path
54. Unzipps a zip file placed at zipURL to path
55. A single checksum calculation for multiple files
56. Put file To Zip File
57. Provides both writing and reading from a file which is transparently compressed in Zip
58. TarInputStream reads a UNIX tar archive as an InputStream
59. TarOutputStream writes a UNIX tar archive as an OutputStream
60. Package files utility
61. Zip Compare
62. Unpack a segment from a zip
63. Unpack a zip file
64. Unzip file to a directory
65. Zip a list of file into one zip file.
66. Validate that an archive contains a named entry
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.