ZipExtractor { public static void extractAll(File zipFile, File destination) throws IOException { try (FileInputStream fs = new FileInputStream(zipFile.toString()); ZipInputStream zipInputStream = new ZipInputStream(fs)) { byte[] buffer = new byte[1024]; ZipEntry zipEntry = zipInputStream.getNextEntry(); while (zipEntry != null) { extractEntry(destination.toPath().normalize().toFile(), zipInputStream, buffer, zipEntry); zipEntry = zipInputStream.getNextEntry(); } } }  static void extractAll(File zipFile, File destination);  }
@Test public void testZipExtractor() throws IOException { File zipFileFolder = temporaryFolder.newFolder(); StringBuilder sb = new StringBuilder(); sb.append("Test String"); File zipFile = zipFileFolder.toPath().resolve("zipFile.zip").toFile(); try (FileOutputStream fos = new FileOutputStream(zipFile); ZipOutputStream out = new ZipOutputStream(fos)) { ZipEntry e = new ZipEntry("testText.txt"); out.putNextEntry(e); byte[] data = sb.toString().getBytes(); out.write(data, 0, data.length); out.closeEntry(); } File unzipFolder = temporaryFolder.newFolder(); ZipExtractor.extractAll(zipFile, unzipFolder); assertThat(unzipFolder.list()).contains("testText.txt"); assertThat(Files.readAllLines(Paths.get(unzipFolder.toString(), "testText.txt"))).containsExactly("Test String"); }