In this tutorial you will see 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.In this Example, We will discuss the use isDirectory method of ZipEntry class.
The
ZipEntry class is used show the single entry in ZIP file. The ZipEntery class
provides
methods for retrieving informationrelated to entry. The ZipEntry class is available in
java.util.zip package.
The isDirectory method of ZipEntry class returns Boolean
value either true
or false, if given file is directory then returns true otherwise returns false.
In this Example, We will discuss about the isDirectory method and how
to extract zip file.
The ZipFele
class create an object of given zip file and read entries. The Enumeration class
create an object . The entries() method of ZipFile class returns enumeration
of the zip file.
The hasMoreElements() of method of Enumeration class
checks availability of entry. The
nextElements() of Enumeration
class returns next elements of enumeration. The isDirectory
method of ZipEntry class check given file is directory or not.The getName
method of ZipEntry
class return the name of associated entry. The
mkdir() method of File class creates directory
of specific name.
About ZIPEntry API:
Return Type | Method | Description |
Boolean | isDirectory() | The isDirectory() Method returns true if zip file is directory otherwise false. |
String | getName() | The method getName() returns name of the associated entry. |
void | write(byte buffer, int offset, int length) | The write(..) method writes an array of bytes onto the associated stream. |
import java.io.*;
|
C:\>java ZipDirectory C:\Work\Bharat\today\directory\file.zip Name of Extract directory : data/ Name of Extract directory : data/New Folder/ Name of Extract fille : data/New Folder/url.txt Name of Extract directory : design/ Name of Extract fille : design/dark_pixel.gif Name of Extract fille : design/donate.gif |