In this tutorial you will see how to extracting the zip file.
In this tutorial you will see how to extracting the zip file.In this Example, we will discuss how to extract a ZIP file. We will use ZipInputStream class for creating input stream that take input from ZIP file. The ZipInputStream class is available in java.util.zip package.
With the help of example code, we can extract given file. The ZipInputStream class will create a input stream and read entry from given Zip file. The getNextEntry method of ZipInputStream class is used to read next ZIP file entry and put the stream at the beginning of the entry data, and the getName method of ZipEntry class return the name of associated entry. The write( byte b, int offset, int length) method of FileOutputStream class is used to write array of bytes..
About ZIPOutputStream API:
The java.util.zip.ZIPInputStream class extends java.io.InflaterIntputStream class. It provides following methods:
Return Type | Method | Description |
void | close() | The close() is use to close all associated stream. |
void | closeEntry() | The closeEntry() method close currently associated stream and put input stream to read next entry.. |
protected zipentry |
createZipEntry() | The createZipEntry() method create new object for given entry name. |
zipentry | getNextEntry() | The getNextEntry() method read next ZIP file entry and put stream at the beginning of the entry data. |
int | read( byte b, int off, int len ) | The read (.....) method read from associated ZIP entry into array of bytes. |
long | skip( int n) | Function skip specified number from input stream. |
import java.io.*; |
C:\>java ExtractZipFile Name of current Zip Entry : testfile2.txt Name of Zip Entry : testfile2.txt Successfully Extracted File Name : testfile2.txt Name of Zip Entry : testfeli1.txt Successfully Extracted File Name : testfeli1.txt |