Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.apache.commons.io.IOUtils;
- import java.io.*;
- import java.util.Enumeration;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipFile;
- public class UnzipInJava
- {
- public static void main(String[] args) throws IOException {
- String jarFile = "./src/main/my_Jars/myJar1.jar";
- String outputPath = "./out/test123/";
- unzipFile(jarFile, outputPath);
- }
- private static void unzipFile(String zipPath, String outputPath) throws IOException {
- ZipFile zipFile = new ZipFile(zipPath);
- try {
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
- while (entries.hasMoreElements()) {
- ZipEntry entry = entries.nextElement();
- File entryDestination = new File(outputPath, entry.getName());
- if (entry.isDirectory()) {
- entryDestination.mkdirs();
- } else {
- entryDestination.getParentFile().mkdirs();
- InputStream in = zipFile.getInputStream(entry);
- OutputStream out = new FileOutputStream(entryDestination);
- IOUtils.copy(in, out);
- IOUtils.closeQuietly(in);
- out.close();
- }
- }
- } finally {
- zipFile.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement