title: Java - Create a ZIP file with duplicate entries
body: <p>I'd like to create a zip which stores two different files with the same name, but I'm unable (using <code>java.util.zip.ZipOutputStream</code>) due to </p>
  
  <blockquote>
    <p>java.util.zip.ZipException: duplicate entry:</p>
  </blockquote>
  
  <p>exception. I know that it's possible, but I need an advise which library I can use for that purposes. Thanks!</p>
  
  <p>UPD the code I'm using:</p>
  
  <pre><code>File zipFile = new File("C:\\Users\\user\\Desktop\\old.zip");
  File outFile = new File("C:\\Users\\user\\Desktop\\new.zip");
  if(!outFile.exists()) {
      outFile.getParentFile().mkdirs();
      outFile.createNewFile();
  }
  
  byte[] buf = new byte[1024];
  ZipInputStream zin = new ZipInputStream(new FileInputStream(zipFile));
  ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFile));
  
  ZipEntry entry = zin.getNextEntry();
  while (entry != null) {
      String name = entry.getName();
      out.putNextEntry(new ZipEntry(name));
      int len;
      while ((len = zin.read(buf)) &gt; 0) {
          out.write(buf, 0, len);
      }
      entry = zin.getNextEntry();
  
      if("file".equals(name)) {
          File fakeFile = new File("C:\\Users\\user\\Desktop\\file");
          InputStream in = new FileInputStream(fakeFile);
          out.putNextEntry(new ZipEntry("file"));
          while ((len = in.read(buf)) &gt; 0) {
              out.write(buf, 0, len);
          }
          out.closeEntry();
          in.close();
      }
  } 
  zin.close();
  out.close();
  </code></pre>