title: How to Extract zip File from jar file
body: <p>I am having a zip file into my project. When I am running my code through IDE, my <code>extract(String file, String destination)</code> method works fine.</p>
  
  <pre><code> D:/Tools/JAVA/Lodable_Creation/build/classes/ib2.zip--&gt;
   String s1=getClass().getResource("Test.zip").getPath().toString();
    extract(s1, "c:\\");
  </code></pre>
  
  <p>This is giving me Path  <code>s1 is--&gt; D:\Tools\JAVA\Lodable_Creation\build</code></p>
  
  <p>When I compile same code and run through Command prompt </p>
  
  <pre><code>file:/D:/Tools/JAVA/Lodable_Creation/dist/Lodable_Creation.jar!/Test.zip
  s1 is--&gt;D:\Tools\JAVA\Lodable_Creation\dist
  </code></pre>
  
  <p>And I am not getting output. Please help me.</p>
  
  <p><strong>UPDATE:-</strong></p>
  
  <pre><code>public static void extract(String file, String destination) throws IOException {
      ZipInputStream in = null;
      OutputStream out = null;
      try {
        // Open the ZIP file
        in = new ZipInputStream(new FileInputStream(file));
        // Get the first entry
        ZipEntry entry = null;
        while ((entry = in.getNextEntry()) != null) {
          String outFilename = entry.getName();
          // Open the output file
          if (entry.isDirectory()) {
            new File(destination, outFilename).mkdirs();
          } else {
            out = new FileOutputStream(new File(destination,outFilename));
            // Transfer bytes from the ZIP file to the output file
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) &gt; 0) {
              out.write(buf, 0, len);
            }
            out.close();
          }
        }
      } finally {
        // Close the stream
        if (in != null) {
          in.close();
        }
        if (out != null) {
          out.close();
        }
      }
    }
  </code></pre>
  
  <p><strong><code>On Ok Click button</code></strong></p>
  
  <pre><code>Map map = System.getenv();
   Set keys = map.keySet();
   String newString  = (String) map.get("CYGWIN_HOME");
   System.out.println(" " + newString);
   String  destination= newString.replace(";", "");
   System.out.println(" " + destination);
   String S =getClass().getResource("Test.zip").getPath().toString();
   File jarFile = new File(S);
   String file=jarFile.toString();
   extract(file,destination);
  </code></pre>
  
  <p>This is my actual code for extract method and on <strong>OK Button</strong>. This is extracting Test.zip file to the Destination folder. i.e <code>CYGWIN_HOME</code></p>