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:
|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..|
|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.|
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
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.