Here you can find the source of unzip(File target)
Parameter | Description |
---|---|
target | File to be unzipped. |
Parameter | Description |
---|---|
IOException | an exception |
public static List<File> unzip(File target) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class Main { private static final int BUFFER = 2048; /**// w w w. j ava 2 s . c o m * Unzips a file and return a list of the unziped files. * * @param target File to be unzipped. * @return A lista with the files that where unzipped. * @throws IOException */ public static List<File> unzip(File target) throws IOException { List<File> unzippedFiles = new ArrayList<>(); BufferedOutputStream dest = null; FileInputStream fis = new FileInputStream(target); ZipEntry entry = null; try (ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis))) { while ((entry = zis.getNextEntry()) != null) { int count; byte data[] = new byte[BUFFER]; // write the files to the disk File unf = new File(target.getParentFile().getAbsolutePath() + "/" + entry.getName()); unzippedFiles.add(unf); FileOutputStream fos = new FileOutputStream(unf); dest = new BufferedOutputStream(fos, BUFFER); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); } } return unzippedFiles; } }