code: public static File createFile(String filename)
          throws SecurityException, IOException {
  
          File f = new File(filename);
          if (!f.createNewFile()) {
              if (!destroy(f)) {
                  throw new SecurityException(
                                     "Could not destroy existing file");
              }
              if (!f.createNewFile()) {
                  throw new SecurityException(
                                     "Failed to atomically create new file");
              }
          }
          return f;
      }
docs: Attempts to create a new file in an atomic way.
  If the file already exists, it if first deleted.
  
  @param filename the name of file to create.
  @return the created file.
  @throws SecurityException if the existing file cannot be deleted.
  @throws IOException if an I/O error occurred.