SHARE
TWEET

Untitled

a guest Aug 24th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.apache.commons.io.IOUtils;
  2. import java.io.*;
  3. import java.util.Enumeration;
  4. import java.util.zip.ZipEntry;
  5. import java.util.zip.ZipFile;
  6.  
  7. public class UnzipInJava
  8. {
  9.     public static void main(String[] args) throws IOException {
  10.  
  11.         String jarFile = "./src/main/my_Jars/myJar1.jar";
  12.         String outputPath = "./out/test123/";
  13.  
  14.         unzipFile(jarFile, outputPath);
  15.     }
  16.  
  17.     private static void unzipFile(String zipPath, String outputPath) throws IOException {
  18.         ZipFile zipFile = new ZipFile(zipPath);
  19.         try {
  20.             Enumeration<? extends ZipEntry> entries = zipFile.entries();
  21.             while (entries.hasMoreElements()) {
  22.                 ZipEntry entry = entries.nextElement();
  23.                 File entryDestination = new File(outputPath,  entry.getName());
  24.                 if (entry.isDirectory()) {
  25.                     entryDestination.mkdirs();
  26.                 } else {
  27.                     entryDestination.getParentFile().mkdirs();
  28.                     InputStream in = zipFile.getInputStream(entry);
  29.                     OutputStream out = new FileOutputStream(entryDestination);
  30.                     IOUtils.copy(in, out);
  31.                     IOUtils.closeQuietly(in);
  32.                     out.close();
  33.                 }
  34.             }
  35.         } finally {
  36.             zipFile.close();
  37.         }
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top