code: public static void zipDir(File zipFile, File dirObj) throws Exception {
          // File dirObj = new File(dir);
          if (!dirObj.isDirectory()) {
              System.err.println(dirObj.getName() + " is not a directory");
              System.exit(1);
          }
  
          try {
  
              ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
                      zipFile));
  
              System.out.println("Creating : " + zipFile);
  
              addDir(dirObj, out);
              // Complete the ZIP file
              out.close();
  
          } catch (IOException e) {
              throw new Exception(e.getMessage());
          }
  
      }
docs: Zips the directory and all of it's sub directories
  @param zipFile
  Path of zip file.
  @param dirObj
  Location of test result
  @throws Exception
  It will throw this exception if file not found.