title: java - How to unzip all the files in a specific directory of a zip file?
body: <p>Say I have a .zip file called <strong>Bundles.zip</strong> and directly inside <strong>Bundles.zip</strong>, there are a few files and a few folders. This is what the .zip looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/sarMf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/sarMf.png" alt="Bundles.zip top level screenshot"></a></p>
  
  <p>Now, I want to extract <em>EVERYTHING</em> from the <strong>Bundles</strong> folder. My program already knows the name of the folder that it needs to extract the files from, in this case, <strong>Bundles</strong>. </p>
  
  <p>The <strong>Bundles</strong> folder inside the zip can have files, subfolders, files in the subfolders, basically anything, like this:</p>
  
  <p><a href="https://i.stack.imgur.com/e8XsG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/e8XsG.png" alt="Bundles.zip inner folder screenshot"></a></p>
  
  <p>And I just need to extract everything from the <strong>Bundles</strong> folder to an output directory.</p>
  
  <p>How can I accomplish this in Java? I have found answers which extract all the files and folders inside the zip, but I need  to extract only a specific folder inside the zip, not everything.</p>
  
  <p>Working code so far:</p>
  
  <pre class="lang-java prettyprint-override"><code>            ZipFile zipFile = new ZipFile(mapsDirectory + "mapUpload.tmp");
              Enumeration zipEntries = zipFile.entries();
              String fname;
              String folderToExtract = "";
              String originalFileNameNoExtension = originalFileName.replace(".zip", "");
  
              while (zipEntries.hasMoreElements()) {
                  ZipEntry ze = ((ZipEntry)zipEntries.nextElement());
  
                  fname = ze.getName();
  
                  if (ze.isDirectory()) //if it is a folder
                  {
  
                      if(originalFileNameNoExtension.contains(fname)) //if this is the folder that I am searching for
                      {
                          folderToExtract = fname; //the name of the folder to extract all the files from is now fname
                          break;
                      }
                  }
              }
  
              if(folderToExtract == "")
              {
                  printError(out, "Badly packaged Unturned map error:  " + e.getMessage());
                  return;
              }
  
  
              //now, how do i extract everything from the folder named folderToExtract?
  </code></pre>
  
  <p>For the code so far, the originalFileName is something like "The Island.zip". Inside the zip there is a folder called The Island. I need to find the folder inside the zip file that matches the zip file's name, and extract everything inside that.</p>