Home » Core Java » util » zip

zip

Java Unzip File Example

Java provides us java.util.zip package which contains suitable classes for compressing/decompressing data from Zip and Gzip file formats. You can have a look at this package and all the utility classes that includes, at the documentation of java.util.zip package. In our example we are going to show you how to decompress a zip file and put all the included files ...

Read More »

Java ZIP File Example

In this tutorial we are going to see how to ZIP a file in Java. ZIP is an archive file format that enables data compression and it is mostly used on files and folders. A ZIP file may contain one or more compressed files or folders. Many compression algorithms have been used by several ZIP implementations, which are ubiquitous in ...

Read More »

Decompress a GZIP File in Java example

In the previous tutorial we saw how to compress a File with the GZIP method. In this tutorial we are going to see how to decompress the File that was compressed with the GZIP method. Basically all you have to do to decompress a gzipped file is: Create a FileInputStream to the compressed File. Create a GZIPInputStream to the above ...

Read More »

Compress a File in GZIP format in Java

In this tutorial we are going to see how you can compress a File in Java using the GZIP compression method. So, to perform File compression using GZIP in Java, you have to: Create a FileOutputStream to the destination file, that is the file path to the output compressed file. Create a GZIPOutputStream to the above FileOutputStream. Create a FileInputStream ...

Read More »

Create zip file from directory recursively with ZipOutputStream

In this example we shall show you how to create a zip file from a directory recursively, using ZipOutputStream. We have implemented a method to write a File to a ZipFile, with a ZipOutputStream. It is void addDirToArchive(ZipOutputStream zos, File srcFile). The steps of this method are described below: The method gets the array of Files of abstract pathnames denoting ...

Read More »

Create zip file from multiple files with ZipOutputStream

With this example we are going to demonstrate how to create a zip file from multiple Files with ZipOutputStream, that implements an output stream filter for writing files in the ZIP file format. In short, to create a zip file from multiple Files with ZipOutputStream you should: Create a FileOutputStream to write to the file with the specified name, that ...

Read More »

Create zip file from single file with ZipOutputStream

This is an example of how to create a zip file from a single File with ZipOutputStream. The ZipOutputStream class implements an output stream filter for writing files in the ZIP file format. Creating a zip file from a single File with ZipOutputStream implies that you should: Create a FileOutputStream to write to the file with the specified name, that ...

Read More »

Create zip file from directory with ZipOutputStream

In this example we shall show you how to create a zip file from a directory with ZipOutputStream class, that is an output stream filter for writing files in the ZIP file format. To create a zip file from a directory with ZipOutputStream one should perform the following steps: Create a FileOutputStream to write to the file with the specified ...

Read More »

Extract zip file with subdirectories

With this example we are going to demonstrate how to extract from a ZipFile With Subdirectories. In short, to extract from a ZipFile With Subdirectories you should: Create a new File instance by the given pathname of the file. Create a directory with the same name to which the contents will be extracted, using mkdir() API method of File. Create ...

Read More »

Search file in a zip file

This is an example of how to search a File in a zip file, using the ZipFile class. Searching a File in a zip file implies that you should: Create a new ZipFile and open it for reading. Get the enumeration of the ZipFile entries, with entries() API method of ZipFile and iterate through each one of them. For each ...

Read More »