ZipUtil { public static void unzipFile(File zip, File dir) throws IOException { InputStream in = null; OutputStream out = null; ZipFile zipFile = new ZipFile(zip); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (!entry.getName().endsWith("/")) { File unzippedFile = new File(dir, entry.getName()); try { in = zipFile.getInputStream(entry); unzippedFile.getParentFile().mkdirs(); out = new FileOutputStream(unzippedFile); IOUtils.copy(in, out); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } } } private  ZipUtil(); static void unzipFile(File zip, File dir); static void zipDirectory(File directory, File zipFile);  }
@Test public void testUnzip() throws Exception { File zipArchive = createZipForTesting(); File tempDir = FileUtil.createTempDirectory(); ZipUtil.unzipFile(zipArchive, tempDir); assertTrue(new File(tempDir, "a.txt").isFile()); assertTrue(new File(tempDir, "b.txt").isFile()); assertTrue(new File(tempDir, "subdir").isDirectory()); assertTrue(new File(tempDir, "subdir/a.txt").isFile()); }