How do I unzip the contents of a zip file?
Author: Deron Eriksson
Description: This Java tutorial describes how to unzip the contents of a zip file.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0)
(Continued from page 1)
The execution of our ExtractZipContents class with the test.zip file is shown in the Console view below.
If we examine our project now, we can see that f1/f2/f3/file5.txt, folder/f3.txt, folder/f4.txt, f1.txt, and f2.txt were created, as expected. I opened the files, and they extracted correctly.
As you can see, using the java.util.zip package along with some standard JavaSW file and stream code makes it easy to extract the files within a zip file.