Unzips a directory to a folder. @param input a zip file @param destinationDir where the zip will be extracted to
(File input, File destinationDir)
| 175 | * @param destinationDir where the zip will be extracted to |
| 176 | */ |
| 177 | public static void unzip(File input, File destinationDir) throws IOException { |
| 178 | try (ZipInputStream zipInput = new ZipInputStream(new BufferedInputStream(new FileInputStream(input)))) { |
| 179 | ZipEntry entry; |
| 180 | while ((entry = zipInput.getNextEntry()) != null) { |
| 181 | File dest = new File(destinationDir, entry.getName()); |
| 182 | if (entry.isDirectory()) { |
| 183 | FileMisc.mkdirs(dest); |
| 184 | } else { |
| 185 | FileMisc.mkdirs(dest.getParentFile()); |
| 186 | try (OutputStream output = new BufferedOutputStream(new FileOutputStream(dest))) { |
| 187 | copy(zipInput, output); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |