title: Java.util.zip.ZipException: invalid entry size (expected 18401 but got 0 bytes) when using putNextEntry() in ZipOutputStream?
body: <p>I converted a zip file of 5 files into a byte array. I want to output a zip file on my disk from that bytearray. My process was first reading the byte[] into a ByteArrayInputStream then into a ZipInputStream.</p>
  <pre><code>InputStream plainTextStream = new ByteArrayInputStream(plainText);
  ZipInputStream zipInStream = new ZipInputStream(plainTextStream);
  </code></pre>
  <p>I want this to be outputted into a zip file on my disk so here I thought I will need a file and a ZipOutPutStream passing that zip file.</p>
  <pre><code>ZipOutputStream zipOutStream = new ZipOutputStream(new FileOutputStream(file));
  </code></pre>
  <p>With a zip entry I traversed the ZipInPutStream writing to a FileOutputStream each entry, using a buffer. At the end of each main loop I put an entry into the ZipOutPutStream.</p>
  <pre><code>    ZipEntry entry = null;
      while((entry = zipInStream.getNextEntry()) != null){
          FileOutputStream fileOutStream = new FileOutputStream(entry.getName());
          byte[] byteBuff = new byte[1024];
          int bytesRead = 0;
          while ((bytesRead = zipInStream.read(byteBuff)) != -1)
          {
              fileOutStream.write(byteBuff, 0, bytesRead);
          }
          fileOutStream.close();
          zipOutStream.putNextEntry(entry);
          zipInStream.closeEntry();
      }
  </code></pre>
  <p>I add the first file from the zip (there are 5 files), but when trying to add the 2nd file, I get an error on</p>
  <pre><code>zipOutStream.putNextEntry(entry)
  
  java.util.zip.ZipException: invalid entry size (expected 18401 but got 0 bytes)
  </code></pre>
  <p>Through debugging I can't figure out where it goes wrong. I assume it may have something to do with the buffer when putting in the first outputstream(entry.getName())? The bytesRead while loop could be an issue.
  This is all assuming the logic makes sense. I hope I can approach a solution to this error.</p>