code: public static void deleteIfExists(File file) throws IOException {
      if (file.exists()) {
        if (file.isFile()) {
          if (!file.delete()) {
            throw new IOException("Delete file failure,path:" + file.getAbsolutePath());
          }
        } else {
          File[] files = file.listFiles();
          if (files != null && files.length > 0) {
            for (File temp : files) {
              deleteIfExists(temp);
            }
          }
          if (!file.delete()) {
            throw new IOException("Delete file failure,path:" + file.getAbsolutePath());
          }
        }
      }
    }
docs: 删除文件或文件夹