title: Java get the top level folder from zip file
body: <p>I kind of stuck in this problem. I want to print only the top level directory from a zip file. For example I have a zip file with following structure:</p>
  
  <pre><code>Sample.zip
      - sound
            - game
                  -start.wav
                  -end.wav
            - Intro
      - custom
            - Scene
                  - fight
            - Angle
         ..............
  </code></pre>
  
  <p>Above figure shows: the Sample.zip has 2 folders (sound and custom), and inside sound there are 2 folders game and Intro and so on...</p>
  
  <p>Now I know how to open and grab the directory from zip file: For example (working code)</p>
  
  <pre><code>try {
      appFile = ("../../Sample.zip"); // just the path to zip file
      ZipFile zipFile = new ZipFile(appFile);
      Enumeration&lt;? extends ZipEntry&gt; entries = zipFile.entries();
      while (entries.hasMoreElements()) {
          ZipEntry entry = entries.nextElement();
          if(entry.isDirectory()){
              String dir = entry.getName();
              File file = new File(dir);
              System.out.println(file.getParent());
          }
      }
  } catch (IOException e) {
      System.out.println("Error opening Zip" +e);
  }
  </code></pre>
  
  <p>Now I also know I can use <code>.getParent()</code>(as you see above) to get the top level dir, but the above implementation has not worked. It'll list out all the directory , like</p>
  
  <pre><code> null   
   sound
   game
   null
   custom
   scene
   Angle 
  </code></pre>
  
  <p>My question is how can I actually print only the top level folders, In above scenario , <code>sound</code> and <code>custom</code> ?</p>
  
  <p>For any sort of hint, I'll be thankful.</p>