public static void createZip(Path zipFile,Path toBeAdded,String internalPath){
  Map<String,String> env=new HashMap<>();
  try {
    env.put("create",String.valueOf(!Files.exists(zipFile)));
    URI fileUri=zipFile.toUri();
    URI zipUri=new URI("jar:" + fileUri.getScheme(),fileUri.getPath(),null);
    try (FileSystem zipfs=FileSystems.newFileSystem(zipUri,env)){
      Path internalTargetPath=zipfs.getPath(internalPath);
      if (!Files.exists(internalTargetPath.getParent())) {
        Files.createDirectory(internalTargetPath.getParent());
      }
      Files.copy(toBeAdded,internalTargetPath,StandardCopyOption.REPLACE_EXISTING);
    }
   }
 catch (  Exception e) {
    LOGGER.error("Failed to create zip file!" + e.getMessage());
  }
}

public static void createZip ( Path zipFile , Path toBeAdded , String internalPath ) { Map < String , String > env = new HashMap < > ( ) ; try { env . put ( "create" , String . valueOf ( ! Files . exists ( zipFile ) ) ) ; URI fileUri = zipFile . toUri ( ) ; URI zipUri = new URI ( "jar:" + fileUri . getScheme ( ) , fileUri . getPath ( ) , null ) ; try ( FileSystem zipfs = FileSystems . newFileSystem ( zipUri , env ) ) { Path internalTargetPath = zipfs . getPath ( internalPath ) ; if ( ! Files . exists ( internalTargetPath . getParent ( ) ) ) { Files . createDirectory ( internalTargetPath . getParent ( ) ) ; } Files . copy ( toBeAdded , internalTargetPath , StandardCopyOption . REPLACE_EXISTING ) ; } } catch ( Exception e ) { LOGGER . error ( "Failed to create zip file!" + e . getMessage ( ) ) ; } }
creates ( or adds ) a file to a zip
