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.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:
The Adler32 class is used to to compute the Adler-32 checksum of a data stream.
The CheckedInputStream class maintains the checksum of the data.
The CheckedOutputStream class also maintain the checksum data of output stream data.
The CRC32 is a class that can is used to compute the CRC-32 of a data stream.
The Deflater class provides support for general purpose compression using the popular ZLIB compression library.
The DeflaterOutputStream class implements an output stream filter for compressing data in the "deflate" compression format.
The GZIPInputStream class implements a stream filter for reading compressed data in the GZIP format.
The GZIPOutputStream class implements a stream filter for writing compressed data in the GZIP file format.
The Inflater class provides support for general purpose decompression. It uses the popular ZLIB compression library for decompressing the data.
The InflaterInputStream class implements a stream filter, which is used for uncompressing data in the "deflate" compression format.
The ZipEntry class is used to represent a ZIP file entry.
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.
The ZipInputStream class implements an input stream filter for reading files in the ZIP file format.
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:
The DataFormatException exception signals the occurrence of a data format.
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:
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.