title: Java, creating two identical zip files if content are the same
body: <p>I have this, which works fine for zipping and unzipping: </p>
  
  <pre><code>    public static final String SLASH = "/";
      public static void zip(int level, File zipfile, File... files) throws IOException {
              try (FileOutputStream fo = new FileOutputStream(zipfile); ZipOutputStream zo = new ZipOutputStream(fo)) {
                      zo.setLevel(level);
  
                      for (File file : files) {
                              zip("", file, zo);
                      }
  
                      zo.flush();
                      zo.finish();
                      zo.close();
  
                      // !!!!!!!! Tried these !!!!!!!!!
                      long time = Cal.date(1970, Cal.Month.JANUARY, 1).getTime();
                      zipfile.setLastModified(time);
                      Files.setAttribute(zipfile.toPath(), "lastAccessTime", FileTime.fromMillis(time) );
              }
      }
  
      public static File unzip(File zipfile, File to) throws IOException {
              ZipFile                         filezipped = new ZipFile( zipfile );
              Enumeration&lt;? extends ZipEntry&gt; entries    = filezipped.entries( ) ;
  
              while ( entries.hasMoreElements() ) {
  
                      ZipEntry zipEntry = entries.nextElement( )             ;
                      File     file     = new File( to, zipEntry.getName( ) );
  
                      if ( zipEntry.isDirectory() ) {
                              file.mkdirs();
                      }
                      else {
                              file.getParentFile().mkdirs();
                              try ( InputStream in = filezipped.getInputStream(zipEntry) ) {
                                      Files.copy( in, file.toPath() );
                              }
                      }
              }
  
              return zipfile;
      }
  
      private static void zip(String base, File file, ZipOutputStream zo) throws IOException {
              String path   = base + file.getName();
              if ( file.isDirectory() ) {
                      path += SLASH;
  
                      zo.putNextEntry( new ZipEntry(path) );
  
                      for (File ff : file.listFiles()) {
                              zip(path, ff, zo);
                      }
  
                      zo.closeEntry();
  
              } else {
                      zo.putNextEntry( new ZipEntry(path) );
  
                      Files.copy(file.toPath(), zo);
  
                      zo.closeEntry();
              }
      }
  </code></pre>
  
  <p>However, the zip file will have a different checksum even though the content of the file is unchanged. This is a problem when committing the files using git. </p>
  
  <p><strong>How can I ensure that the zipped file stays the same every time unless content has changed?</strong></p>