Java ZipFileZIP is a file format for compressed files or folders. It enables data compression. Using Java programming language, we can create ZIP files or folders. For this Java provides the classes In Java, ZipFile is a class that belongs to the java.util.zip package. The package provides the java.util.zip package. The package contains the number of classes that deal with the ZIP file or folder. The classes can be to read and write the standard ZIP and GZIP file formats. In this section, we will discuss the Java ZipFile class. Java ZipFile ClassIt provides fields and methods that are required to deal with the ZIP file. The class is useful if we want to read entries from a ZIP file. It implements the Closeable and AutoCloseable interfaces. ZipFile Class FieldsThe class provides the constant field's values that are public static and final. Modifier and Type | Field |
---|
static int | CENATT | static int | CENATX | static int | CENCOM | static int | CENCRC | static int | CENDSK | static int | CENEXT | static int | CENFLG | static int | CENHDR | static int | CENHOW | static int | CENLEN | static int | CENNAM | static int | CENOFF | static long | CENSIG | static int | CENSIZ | static int | CENTIM | static int | CENVEM | static int | CENVER | static int | ENDCOM | static int | ENDHDR | static int | ENDOFF | static long | ENDSIG | static int | ENDSIZ | static int | ENDSUB | static int | ENDTOT | static int | EXTCRC | static int | EXTHDR | static int | EXTLEN | static long | EXTSIG | static int | EXTSIZ | static int | LOCCRC | static int | LOCEXT | static int | LOCFLG | static int | LOCHDR | static int | LOCHOW | static int | LOCLEN | static int | LOCNAM | static long | LOCSIG | static int | LOCSIZ | static int | LOCTIM | static int | LOCVER | static int | OPEN_DELETE Mode flag to open a zip file and mark it for deletion. | static int | OPEN_READ Mode flag to open a zip file for reading. |
ZipFile Class ConstructorsPassing null values to the constructors may lead to the NullPointerException. Constructor | Description |
---|
ZipFile(File file) | It is used to open a specified file object file. | ZipFile(File file, Charset charset) | It is used to open a ZIP file for reading. | ZipFile(File file, int mode) | It opens a new ZipFile to read from the specified File object in the specified mode. | ZipFile(File file, int mode, Charset charset) | It opens a new ZipFile to read from the specified File object in the specified mode. | ZipFile(String name) | It also opens a ZIP file for reading. | ZipFile(String name, Charset charset) | It is also used to open a ZIP file for reading. |
ZipFile Class MethodsThe class has the following methods. Method | Description |
---|
close() | The method closes the ZIP file. | entries() | It returns the enumeration of the ZIP file entries. | finalize() | It ensures that the system resources held by this ZipFile object are released when there are no more references to it. It overrides the finalize method of the Object class. | getComment() | It returns the ZIP file comment and returns null if the file has no comment. | getEntry() | It returns the ZIP file entry for the specified name and returns null if the entry is null. | getInputStream() | It is used to read the contents of the specified ZIP file entry and returns an input stream for the same. | getName() | It is used to get the path of the ZIP file. | size() | It is used to get the number of entries a ZIP file has. |
|