code: public static boolean deleteFileOrDirOnExit( File filehandle ) {
          if (filehandle.isDirectory()) {
              String[] children = filehandle.list();
              for( int i = 0; i < children.length; i++ ) {
                  boolean success = deleteFileOrDir(new File(filehandle, children[i]));
                  if (!success) {
                      return false;
                  }
              }
          }
          filehandle.deleteOnExit();
          return true;
      }
docs: Delete file or folder recursively on exit of the program
  
  @param filehandle
  @return true if all went well