code: public static Action deleteFile(final String path, final String tempDir) {
          if (path == null)
              throw new IllegalArgumentException("The path variable cannot be null");
          if (tempDir == null)
              throw new IllegalArgumentException("The tempDir variable cannot be null");
  
          final File tempFile = new File(tempDir, Misc.CreateUUID());
          final AtomicBoolean exists = new AtomicBoolean();
          return new Action(
              // Perform:
              new ActionBlock() {
                  @Override
                  public void execute() throws ActionException {
                      File file = new File(path);
                      if (file.exists()) {
                          if (tempFile == null)
                              throw new ActionException("Cannot perform file deletion as " +
                                      "the temporary file cannot be crated.");
  
                          boolean success = new File(path).renameTo(tempFile);
                          exists.set(success);
                          if (success)
                              // Mark delete on exit (optional and work on Java only):
                              tempFile.deleteOnExit();
                          else
                              throw new ActionException("Cannot move file " + path +
                                      " to " + tempFile.getAbsolutePath());
                      }
                  }
              },
              // Backout:
              new ActionBlock() {
                  @Override
                  public void execute() throws ActionException {
                      if (exists.get()) {
                          if (!tempFile.renameTo(new File(path)))
                              throw new ActionException("Cannot move file " +
                                      tempFile.getAbsolutePath() + " to " + path);
                      }
                  }
              },
              // Cleanup:
              new ActionBlock() {
                  @Override
                  public void execute() throws ActionException {
                      if (exists.get()) {
                          if (tempFile.isDirectory()) {
                              if (!FileDirUtils.deleteRecursive(tempFile))
                                  throw new ActionException("Cannot delete the temporary directory " +
                                          tempFile.getAbsolutePath());
                          } else {
                              if (!tempFile.delete())
                                  throw new ActionException("Cannot delete the temporary file " +
                                          tempFile.getAbsolutePath());
                          }
                      }
                  }
              });
      }
docs: Deletes the file/directory at the given path, if it exists.
  @param path Path to the file or directory to be deleted
  @param tempDir Path to a tem directory used for backing out the deleted file
  @return A delete file Action