List of usage examples for java.util.zip ZipFile ZipFile
public ZipFile(File file, int mode, Charset charset) throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { ZipFile zipFile = new ZipFile(new File("testfile.zip"), ZipFile.OPEN_READ, Charset.defaultCharset()); ZipEntry entry = zipFile.getEntry("fileName"); }
From source file:com.blackducksoftware.integration.hub.detect.util.DetectZipUtil.java
public static void unzip(File zip, File dest, Charset charset) throws IOException { Path destPath = dest.toPath(); try (ZipFile zipFile = new ZipFile(zip, ZipFile.OPEN_READ, charset)) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); Path entryPath = destPath.resolve(entry.getName()); if (!entryPath.normalize().startsWith(dest.toPath())) throw new IOException("Zip entry contained path traversal"); if (entry.isDirectory()) { Files.createDirectories(entryPath); } else { Files.createDirectories(entryPath.getParent()); try (InputStream in = zipFile.getInputStream(entry)) { try (OutputStream out = new FileOutputStream(entryPath.toFile())) { IOUtils.copy(in, out); }/* w w w . j av a 2 s . c om*/ } } } } }