title: Error while extracting a zip file
body: <p>I am trying to unzip a compressed folder using java.util.zip package:</p>
  
  <p>Now my compressed folder structure is :
  My compressed folder name is classes.zip
  Inside this zip folder i have a classes folder inside that i have sub folders as well as files:
  <a href="https://i.stack.imgur.com/d47EQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d47EQ.png" alt="enter image description here"></a></p>
  
  <p>If you further go inside the www folder then again it has sub folder which is a java package and inside the package structured folder i have .class files.</p>
  
  <p>Now i am trying to unzip this compressed folder and my code is:
  package www.eor.com;</p>
  
  <pre><code>/**
  
  * A console application that tests the UnzipUtility class
   *
   */
  public class UnzipUtilityTest {
      public static void main(String[] args) {
          String zipFilePath = "D:/classes.zip";
          String destDirectory = "D:/Dojo";
          UnzipUtility unzipper = new UnzipUtility();
          try {
              unzipper.unzip(zipFilePath, destDirectory);
          } catch (Exception ex) {
              // some errors occurred
              ex.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>and the supporting class is :</p>
  
  <pre><code>package www.eor.com;
  
  import java.io.BufferedOutputStream;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.util.zip.ZipEntry;
  import java.util.zip.ZipInputStream;
  
  /**
   * This utility extracts files and directories of a standard zip file to
   * a destination directory.
   */
  public class UnzipUtility {
      /**
       * Size of the buffer to read/write data
       */
      private static final int BUFFER_SIZE = 4096;
      /**
       * Extracts a zip file specified by the zipFilePath to a directory specified by
       * destDirectory (will be created if does not exists)
       * @param zipFilePath
       * @param destDirectory
       * @throws IOException
       */
      public void unzip(String zipFilePath, String destDirectory) throws IOException {
          File destDir = new File(destDirectory);
          if (!destDir.exists()) {
              destDir.mkdir();
          }
          ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
          ZipEntry entry = zipIn.getNextEntry();
          // iterates over entries in the zip file
          while (entry != null) {
              String filePath = destDirectory + File.separator + entry.getName();
              if (!entry.isDirectory()) {
                  // if the entry is a file, extracts it
                  extractFile(zipIn, filePath);
              } else {
                  // if the entry is a directory, make the directory
                  File dir = new File(filePath);
                  dir.mkdir();
              }
              zipIn.closeEntry();
              entry = zipIn.getNextEntry();
          }
          zipIn.close();
      }
      /**
       * Extracts a zip entry (file entry)
       * @param zipIn
       * @param filePath
       * @throws IOException
       */
      private void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
          BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
          byte[] bytesIn = new byte[BUFFER_SIZE];
          int read = 0;
          while ((read = zipIn.read(bytesIn)) != -1) {
              bos.write(bytesIn, 0, read);
          }
          bos.close();
      }
  }
  </code></pre>
  
  <p>Now when i run <strong>UnzipUtilityTest</strong> class it is giving me exception as :</p>
  
  <pre><code>java.io.FileNotFoundException: D:\Dojo\classes\camel-config-xml.xml (The system cannot find the path specified)
      at java.io.FileOutputStream.open(Native Method)
      at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:221)
      at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:110)
      at www.cognizant.com.UnzipUtility.extractFile(UnzipUtility.java:59)
      at www.cognizant.com.UnzipUtility.unzip(UnzipUtility.java:41)
      at www.cognizant.com.UnzipUtilityTest.main(UnzipUtilityTest.java:16)
  </code></pre>
  
  <p>Why it is giving this exception and how to rectify this problem?</p>