code: public static void compressDirectory(File rootPath, File dstZipPath) throws IOException
     {
        ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(dstZipPath));
        try
        {
           if (rootPath.isDirectory())
           {
              String[] files = rootPath.list();
              if (files == null || files.length == 0)
              {
                 // In java 7 no ZipException is thrown in case of an empty directory
                 // so to remain compatible we need to throw it explicitly
                 throw new ZipException("ZIP file must have at least one entry");
              }
              for (int i = 0; i < files.length; i++)
              {
                 compressDirectory("", new File(rootPath, files[i]), zip);
              }
           }
           else
           {
              compressDirectory("", rootPath, zip);
           }
        }
        finally
        {
           if (zip != null)
           {
              zip.flush();
              zip.close();
           }
        }
     }
docs: Compress data. In case when <code>rootPath</code> is a directory this method
  compress all files and folders inside the directory into single one. IOException
  will be thrown if directory is empty. If the <code>rootPath</code> is the file
  the only this file will be compressed.
  
  @param rootPath
  the root path, can be the directory or the file
  @param dstZipPath
  the path to the destination compressed file
  @throws IOException
  if any exception occurred