Extract contents of a zip file

This example shows how to extract a zip file containing one file (or entry).
The name of the zip file is ‘compressed.zip’ and we want to write the contents to a file called ‘extracted.txt’.
We start by opening an input stream to the compressed file and an output stream to the file where we want the content to be extracted.
After that we get the next entry of the zip file (and the only entry in this case) and test so it’s not null, and then start reading the contents from the input stream and writing each chunk read from that input stream to the output stream.
As usual we should clean up properly afterwards so we close the input and output streams.

Search for more Java info on this site here:
Custom Search

Please type any questions here.