code: public static void removeDirectory(File dir) throws IOException
     {
        if (dir.isDirectory())
        {
           for (File subFile : dir.listFiles())
           {
              removeDirectory(subFile);
           }
  
           if (!dir.delete())
           {
              throw new IOException("Can't remove folder : " + dir.getCanonicalPath());
           }
        }
        else
        {
           if (!dir.delete())
           {
              throw new IOException("Can't remove file : " + dir.getCanonicalPath());
           }
        }
     }
docs: Remove directory.
  
  @param dir
  directory to remove
  @throws IOException
  if any exception occurred