code: private static void addDir(File dirObj, ZipOutputStream out)
              throws IOException {
          File[] dirList = dirObj.listFiles();
          byte[] tmpBuf = new byte[1024];
  
          for (int i = 0; i < dirList.length; i++) {
              if (dirList[i].isDirectory()) {
                  addDir(dirList[i], out);
                  continue;
              }
  
              FileInputStream in = new FileInputStream(
                      dirList[i].getAbsolutePath());
              System.out.println(" Adding: " + dirList[i].getAbsolutePath());
  
              out.putNextEntry(new ZipEntry(dirList[i].getAbsolutePath()));
  
              // Transfer from the file to the ZIP file
              int len;
              while ((len = in.read(tmpBuf)) > 0) {
                  out.write(tmpBuf, 0, len);
              }
  
              // Complete the entry
              out.closeEntry();
              in.close();
          }
      }
docs: Add directory to zip file
  @param dirObj
  @param out
  @throws IOException