Home Tutorial Java Corejava Zip Java zip package - Learn how to use java zip package.

 
 

Share on Google+Share on Google+
Java zip package - Learn how to use java zip package.
Posted on: July 8, 2010 at 12:00 AM
Advertisement
In this section we will learn about java.util.zip package of java library. We will also learn how to use the zip API to create and read the zip and gzip files within java program.

Java zip package

In this section we will learn about java.util.zip package of java library. We will also learn how to use the zip API to create and read the zip and gzip files within java program.

The zip format is very easy method of storing and distributing the file of any type, such as programming code, music, videos etc.. The java.util.zip package contains the api for manipulating the archive files. The java zip package provides the API for reading and writing the standard ZIP and GZIP file formats. With the help of classes of zip package you can create, read and update the zip achieve files.

The java.util.zip package contains an Interface called Checksum, which is the representation of checksum data.

It contains the following classes:

Adler32:
The Adler32 class is used to to compute the Adler-32 checksum of a data stream.

CheckedInputStream:
The CheckedInputStream class maintains the checksum of the data.

CheckedOutputStream:
The CheckedOutputStream  class also maintain the checksum data of output stream data.

CRC32:
The CRC32 is a class that can is used to compute the CRC-32 of a data stream.

Deflater:
The Deflater class provides support for general purpose compression using the popular ZLIB compression library.

DeflaterOutputStream:
The DeflaterOutputStream class implements an output stream filter for compressing data in the "deflate" compression format.

GZIPInputStream:
The GZIPInputStream class implements a stream filter for reading compressed data in the GZIP format.

GZIPOutputStream:
The GZIPOutputStream class implements a stream filter for writing compressed data in the GZIP file format.

Inflater:
The Inflater class provides support for general purpose decompression. It uses the popular ZLIB compression library for decompressing the data.

InflaterInputStream:
The InflaterInputStream class implements a stream filter, which is used for uncompressing data in the "deflate" compression format.

ZipEntry:
The ZipEntry class is used to represent a ZIP file entry.

ZipFile:
The ZipFile class is used to read entries from a zip file. With the help of this class you can get the information on the content of the the zip file.

ZipInputStream:
The ZipInputStream class implements an input stream filter for reading files in the ZIP file format.

ZipOutputStream:
The ZipOutputStream class implements an output stream filter for writing files in the ZIP file format.

With the help of classes provided by the java.util.zip package you can handle the zip files effectively within your java program. You write programs to create zip, read and update the zip archive files on the fly.

Exception classes of the java.util.zip package

The exception handling classes in the java.util.zip allows the developers to handle the exceptions in the program at runtime. Here are the details of the exception classes:

DataFormatException:
The DataFormatException exception signals the occurrence of a data format.

ZipException:
The ZipException means the occurrence of some exception in the process.

You can catch these exceptions in your program and then take the appropriate actions.

Here are the few examples of java.util.zip package:

  • Compressing Streams
  • Zip File
  • Zip Folder
  • Unzip File
  • Here is the list of more use of java.util.zip package, these examples will show you how you can create zip files of one more files or directories. Let's learn zip package of java with examples.

    How to read and compare content of two different text file
    In this tutorial you will see how to read and compare content of two different text file.
     
    How to make a zip file in java
    This tutorial discusses the example code of creating a zip file in Java.
     
    How to read a byte.
    This tutorial demonstrate how to read a byte of data from a file.
     
    How to write content of one file to another file.
    This tutorial demonstrate how to write content of one file to another file using CheckedOutputStream class.
     
    How to write content of one file to another file and calculate checksum for accuracy.
    This tutorial demonstrate how to write content of one file to another file and also check for accuracy.
     
    How to make a gzip file in java.
    In this tutorial you will see how to make a gzip file from any given file.
     
    How to extract zip file in java.
    In this tutorial you will see how to extracting the zip file.
     
    How to decompress gzip file in java
    In this tutorial you will see the use of GZIPInputStream for decompress gzip file.
     
    Skip method in java.
    In this tutorial you will see how to use the skip method in java.
     
    Zipentry example in java
    In this tutorial you will see the use of Zipentry class.
     
    String Compression using Deflater class in java
    In this tutorial you will see the use of Deflater class for compressing string.
     
    How to Compress file using Deflater class in java
    In this tutorial you will see the use of Deflater class for compressing the data of a file.
     
    Example of skip() method of CheckedInputStream class.
    In this section we will discuss about skip method of CheckedInputStream class to skip the byte in a given file .
     
    Decompress file using Inflater class.
    In this tutorial we will discuss about decompression of a file using Inflater class.
     
    Use of getTotalIn and getTotalOut method of Deflater class in java.
    In this tutorial you will find the use of getTotalIn and getTotalOut method of Deflater class in java.
     
    Use of getTotalIn and getTotalOut method of Inflater class in java.
    In this tutorial you will see the Use of getTotalIn and getTotalOut method of Inflater class in java.
     
    Calculating the Adler32 checksum of a file.
    In this tutorial you will see how to Calculating the Adler32 checksum of a file.
     
    Use of write method of CheckedOutputStream class in java.
    In this tutorial you will see the use of write(int b) method of CheckedOutputStream class in java.
     
    How to Compress file using DeflaterOutputStram class in java.
    In this tutorial you will see how to Compress file using DeflaterOutputStram class in java.
     
     Use of getBytesRead, getByteWritten and getRemaining method of Inflater class in java.
    In this tutorial, you see use of getBytesRead, getByteWritten and getRemaining method of Inflater class in java.
     
    Use of getMethod, getSize and getTime method of ZipEntry class in java.
    In this tutorial you will see use of getMethod, getSize and getTime method of ZipEntry class in java.
     
    How do Unzip a directory and all its contents using ZipEntry class in java.
    In this tutorial you will see how do Unzip a directory and all its contents using ZipEntry class in java.
     
    How to use update and reset method of CRC32
    In this tutorial you will see how to use update and reset method of CRC32.
     
    Use of setCrc, setSize and getCrc method of ZipEntry class.
    In this tutorial you will see the use of setCrc, setSize and getCrc method of ZipEntry class.
     
    Use of size and getInputStream method of ZipFile.
    In this tutorial you will see the use of size and getInputStream method of ZipFile.
     
    Show all the entries of zip file.
    In this tutorial you will see how to show all the entries of zip file.
     
    How to search entry in ZipFile.
    In this tutorial you will see how to search entry in ZipFile.
     
    Use of setComment and getComment of ZipEntry.
    In this tutorial you will see how to use Use of setComment and getComment of ZipEntry.
     
    How to generate hash code of Zip file.
    In this tutorial you will see how to generate hash code of Zip file.
     
    Advertisement

    Related Tags for Java zip package - Learn how to use java zip package.:


    Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

    Posted on: July 8, 2010

    Recommend the tutorial

    Advertisements Advertisements
     

     

     

    DMCA.com