Delete file only if it already exists.

@param file to delete
555988
public static void deleteIfExists(final File file)
    {
        if (file.exists())
        {
            try
            {
                Files.delete(file.toPath());
            }
            catch (final IOException ex)
            {
                LangUtil.rethrowUnchecked(ex);
            }
        }
    }
269250
public static void checkValidFile(final File file) {
        checkNotNull("file", file);
        if (!file.exists()) {
            throw new IllegalArgumentException("The file '" + file + "' does not exist!");
        }
        if (!file.isFile()) {
            throw new IllegalArgumentException("The name '" + file + "' is not a file!");
        }
    }
668180
private void dealWithFile(File file) {
		// Browse thru Map
		SelectiveFileScannerObserver specificFileScanner = selectiveFileScannerMap.get(file.getName());
		if (specificFileScanner != null) {
			logger.debug("Launching fileScanner={} for file={}", specificFileScanner.getClass(), file.getAbsoluteFile());
			specificFileScanner.scanFile(file);
		}

		// Browse thru List
		for (FileScannerObserver fileScanner : fileScanners) {
			logger.debug("Launching fileScanner={} for file={}", fileScanner.getClass(), file.getAbsoluteFile());
			fileScanner.scanFile(file);
		}
	}
1204272
public static boolean delete(File file) {
        boolean result = false;
        if (file.exists()) {
            result = file.delete();
            if (!result) {
                logger.info("delete " + file.getName() + " error");
            }
        }
        return result;
    }
1028319
public static boolean delete(File f) {
		if (f == null || !f.exists()) return true;
		if (f.isDirectory()) {
			File[] subFiles = f.listFiles();
			if (subFiles != null) {
				for (File sf : subFiles) {
					IOUtil.delete(sf);
				}
			}
		}
		return f.delete();
	}
26633
public void delete() throws IOException {
		File f = tempFile;
		if(f!=null) {
			FileUtils.delete(f);
			tempFile = null;
		}
	}
305507
private boolean delete(final File f) throws IOException {

		if (f.isDirectory()) {

			final File[] files = f.listFiles();
			for (int i = 0; i < files.length; i++) {
				final boolean del = delete(files[i]);
				if (del == false) {
					return false;
				}
			}

		} else {
			return f.delete();
		}

		// Now directory is empty
		return f.delete();
	}
344924
public synchronized boolean needsReload(final File file) throws IOException {
        final long lastMod = file.lastModified();
        if (!file.exists()) {
            mtimes.remove(file);
        }
        final Long aLong = mtimes.get(file);
        return null == aLong || lastMod > aLong;
    }
332480
function( file ) {
            var me = this,
                existing = this._map[ file.id ];

            if ( existing ) {
                delete this._map[ file.id ];
                this._delFile(file);
                file.destroy();
                this.stats.numOfDeleted++;
                
            }
        }
191177
void add(final File file) {
    if (file.isFile()) {
      if (this.fileNames.contains(file.getName())) {
        LOG.log(Level.FINEST, "A file with this name has already been added: {0}", file.getName());
      } else {
        this.fileNames.add(file.getName());
        this.theFiles.add(file);
      }
    } else {
      LOG.log(Level.FINEST, "Ignoring, because it is not a proper file: {0}", file);
    }
  }
174884
private void delete(File file) {

		// Assertions.
		if (file == null) {
			String msg = "Argument 'file' cannot be null.";
			throw new IllegalArgumentException(msg);
		}

		if (file.isDirectory()) {
			for (File f : file.listFiles()) {
				delete(f);
			}
		}

		file.delete();

	}
736752
public static boolean createNewFile(File file) throws IOException {
        createFolder(file.getParent());
        return (!file.exists() || file.delete()) && file.createNewFile();
    }
600757
public static function Delete( string $file )
   {

      if ( ! \file_exists( $file ) )
      {
         // No deleting required
         return;
      }

      try
      {
         \unlink( $file );
         \clearstatcache();
         if ( ! \file_exists( $file ) )
         {
            // Deleting was successful
            return;
         }
      }
      catch ( \Throwable $ex ) { }

      if ( '\\' === DIRECTORY_SEPARATOR )
      {
         $f = \escapeshellarg( $file );
         try { \exec( "del {$f}" ); }
         catch ( \Throwable $ex )
         {
            throw new IOException( $file, 'Deleting the defined file fails!', \E_USER_ERROR, $ex );
         }
         \clearstatcache();
         if ( \file_exists( $file ) )
         {
            throw new IOException(
               $file,
               'Deleting the defined file fails! No known method works.'
            );
         }
         return;
      }

      try { \exec( "unlink {$file}" ); }
      catch ( \Throwable $ex )
      {
         throw new IOException( $file, 'Deleting the defined file fails!', \E_USER_ERROR, $ex );
      }

      \clearstatcache();

      if ( \file_exists( $file ) )
      {
         throw new IOException(
            $file,
            'Deleting the defined file fails!'
         );
      }

   }
490638
public static void recursivelyDelete(File f) throws IOException {
        if (!f.exists()) {
            return;
        }
        if (f.isDirectory()) {
            for (File f1 : f.listFiles()) {
                recursivelyDelete(f1);
            }
            if (!f.delete()) {
                throw new IOException("Unable to delete directory " + f);
            }
        }
        else {
            if (!f.delete()) {
                throw new IOException("Unable to delete file " + f);
            }
        }
    }
949756
public void delete(String fileName) {
		try {
			synchronized (prepareAnchor(fileName)) {
				// Close file, if it was opened
				IoChannel fileChannel = openFiles.remove(fileName);
				if (fileChannel != null)
					fileChannel.close();

				// Delete the file
				boolean hasDeleted = new File(dbDirectory, fileName).delete();
				if (!hasDeleted && logger.isLoggable(Level.WARNING))
					logger.warning("cannot delete file: " + fileName);
			}
		} catch (IOException e) {
			if (logger.isLoggable(Level.WARNING))
				logger.warning("there is something wrong when deleting " + fileName);
			e.printStackTrace();
		}
	}
591295
public void delete() {
    try {
      getDFS().delete(this.path, true);

    } catch (IOException e) {
      e.printStackTrace();
      MessageDialog.openWarning(null, "Delete file",
          "Unable to delete file \"" + this.path + "\"\n" + e);
    }
  }
982531
public void deleteFile(String fileId) throws IOException {
    Preconditions.checkNotNull(fileId, "fileId is required");
    Path p = new Path(fileId);
    if (LOG.isDebugEnabled()) {
      LOG.debug("Deleting path: " + p + " , fileId: " + fileId);
    }
    fileSystem.delete(p, true);
  }