title: How to check if a generated zip file is corrupted?
body: <p>we have a piece of code which generates a zip file on our system. Everything is ok, but sometimes this zip file while opened by FilZip or WinZip is considered to be corrupted.</p>
  
  <p>So here is my question: how can we check programatically if a generated zip file is corrupted?</p>
  
  <p>Here is the code we are using to generate our zip files:</p>
  
  <pre><code>try {
      ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tmpFile));
      byte[] buffer = new byte[16384];
      int contador = -1;
      for (DigitalFile digitalFile : document.getDigitalFiles().getContent()) {
         ZipEntry entry = new ZipEntry(digitalFile.getName());
         FileInputStream fis = new FileInputStream(digitalFile.getFile());
         try {
            zos.putNextEntry(entry);
            while ((counter = fis.read(buffer)) != -1) {
               zos.write(buffer, 0, counter);
            }
            fis.close();
            zos.closeEntry();
         } catch (IOException ex) {
            throw new OurException("It was not possible to read this file " + arquivo.getId());
         }
      }
      try {
        zos.close();
      } catch (IOException ex) {
        throw new OurException("We couldn't close this stream", ex);
      }
  </code></pre>
  
  <p>Is there anything we are doing wrong here?</p>
  
  <p>EDIT:
  Actually, the code above is absolutely ok. My problem was that I was redirecting the WRONG stream for my users. So, instead of opening a zip file they where opening something completely different. Mea culpa :(</p>
  
  <p>BUT the main question remains: <strong>how programatically I can verify if a given zip file is not corrupted?</strong></p>