Java ZIP File Example—refernce
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 many platforms. It is also possible to store a file in a ZIP archive file without compressing it.
Let’s start with a simple example of adding a single file to a ZIP archive.
1. Add a single file to a ZIP archive
In this example we are adding a regular file to a ZIP archive using utility classes.
java. util. zip basically offers two methods to compressed the files that you add in the archive: STORED and DEFLATED. In STORED method,you basically store the files uncompressed,it just stores the raw bytes. DEFLATED on the other hand uses the to perform compression on the files. You can specify which compression algorithm you want to use at each individualZipEntry using setMethod(ZipEntry.STORED) or setMethod(ZipEntry.DEFLATED) ZipEntry API methods.
This was a Java ZIP File Example. You can download the source code of this example here :
The above is all the contents of Java zip file example --- reference collected and sorted out by programming home for you. I hope this article can help you solve the program development problems encountered by Java zip file example --- reference.