title: Unable to extract zip files created from Java
body: <p>I have written a small Java programme as follows to create a zip archive using a provided directory. </p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.util.zip.ZipEntry;
  import java.util.zip.ZipOutputStream;
  
  public class Demo {
  
      public static void main(String[] args) {
  
          FileOutputStream destinationZipOutputStream = null;
          try {
              destinationZipOutputStream = new FileOutputStream("/home/kasun/Downloads/sample/test/compress.zip");
                      } catch (FileNotFoundException e) {
              e.printStackTrace();
          }
          ZipOutputStream updateZipOutputStream = new ZipOutputStream(destinationZipOutputStream);
          updateZipOutputStream.setLevel(ZipOutputStream.STORED);
          File sourceFile = new File("/home/kasun/Downloads/sample/resources");
          try {
              zipFile(sourceFile, "parentdir", updateZipOutputStream);
              updateZipOutputStream.close();
              destinationZipOutputStream.close();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      }
  
      private static void zipFile(File fileToZip, String fileName, ZipOutputStream updateZipOutputStream) throws
              IOException {
  
          if (fileToZip.isHidden()) {
              return;
          }
          if (fileToZip.isDirectory()) {
              // Creating directories with in the zip file
              if (fileName.endsWith("/")) {
                  updateZipOutputStream.putNextEntry(new ZipEntry(fileName));
                  updateZipOutputStream.closeEntry();
              } else {
                  updateZipOutputStream.putNextEntry(new ZipEntry(fileName + "/"));
                  updateZipOutputStream.closeEntry();
              }
              File[] childFiles = fileToZip.listFiles();
              if (childFiles == null) {
                  throw new IOException("IOException occurred when getting list of files of directory " +
                          fileToZip.toString());
              }
              for (File file : childFiles) {
                  zipFile(file, fileName + "/" + file.getName(), updateZipOutputStream);
              }
          } else {
              // Creating files with in the zip file
              try (FileInputStream sourceInputStream = new FileInputStream(fileToZip)) {
                  updateZipOutputStream.putNextEntry(new ZipEntry(fileName));
                  byte[] buffer = new byte[1024];
                  int length;
                  while ((length = sourceInputStream.read(buffer)) &gt; 0) {
                      updateZipOutputStream.write(buffer, 0, length);
                  }
                  updateZipOutputStream.closeEntry();
              }
          }
      }
  }
  </code></pre>
  
  <p>The <code>/home/kasun/Downloads/sample/resources</code> directory used in archive creation contains the following hierarchy</p>
  
  <pre><code> ~/Downloads/sample/resources  pwd
  /home/kasun/Downloads/sample/resources
   ~/Downloads/sample/resources  tree 
  .
  ├── sampledir
  │   └── a
  │       └── b
  │           └── c
  │               └── sample.jar
  ├── sampleFile1.txt
  ├── sampleFile2.txt
  └── sampleFile3.yaml
  
  4 directories, 4 files
  </code></pre>
  
  <p>The above code creates the zip file correctly and it is able to be extracted by executing the following command in terminal,</p>
  
  <pre><code>unzip -q /home/kasun/Downloads/sample/test/compress.zip
  </code></pre>
  
  <p>However, when unzipping from the UI the following error occurs
  <a href="https://i.stack.imgur.com/hQbHL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hQbHL.png" alt="enter image description here"></a></p>
  
  <p>I am using <code>java 1.8.0_171</code> on <code>Ubuntu 18.04</code></p>
  
  <p>====
  As requested in comments please find the -v output as follows,</p>
  
  <pre><code> ✘  ~/Downloads/sample/test  unzip -v compress.zip 
  Archive:  compress.zip
   Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
  --------  ------  ------- ---- ---------- ----- --------  ----
         0  Defl:N        5   0% 2019-03-20 13:55 00000000  parentdir/
      6147  Defl:N     6152  -0% 2019-03-20 13:55 a8ae3168  parentdir/sampleFile1.txt
       642  Defl:N      647  -1% 2019-03-20 13:55 bb00089f  parentdir/sampleFile3.yaml
         0  Defl:N        5   0% 2019-03-20 13:55 00000000  parentdir/sampledir/
         0  Defl:N        5   0% 2019-03-20 13:55 00000000  parentdir/sampledir/a/
         0  Defl:N        5   0% 2019-03-20 13:55 00000000  parentdir/sampledir/a/b/
         0  Defl:N        5   0% 2019-03-20 13:55 00000000  parentdir/sampledir/a/b/c/
    275541  Defl:N   275586   0% 2019-03-20 13:55 d83c1ab3  parentdir/sampledir/a/b/c/sample.jar
        97  Defl:N      102  -5% 2019-03-20 13:55 8b690c25  parentdir/sampleFile2.txt
  --------          -------  ---                            -------
    282427           282512   0%                            9 files
  </code></pre>