Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Wiki Markup
This compliant solution uses the {{Files.delete()}} method from Java 1.7 to delete the file. \[[J2SE 2011|AA. Bibliography#J2SE 11]\] defines {{Files.delete()}} to throw the following exceptions:

Exception

Reason

NoSuchFileException

...

if the file does not exist

...

DirectoryNotEmptyException

...

if the file is a directory and could not otherwise be deleted because the directory is not empty

...

IOException

...

if an I/O error occurs

SecurityException

...

In the case of the default provider, and a security manager is installed, the SecurityManager.checkDelete(String) method is invoked to check delete access to the file

Code Block
bgColor#ccccFF
Path file = new File("file").toPath();
try {
  Files.delete(file);
} catch (IOException x) {
  // handle error
}

...