Some process may be reading / writing a file, so it is locked. Or then your process does not have permission to delete the file. If the file is a directory, all files inside it must be deleted before the directory can be deleted. And finally, there is a situation where the file does not exist, so the delete method will return false.
source share