Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: ok, now i'm done for real

...

Compliant Solution (Java 1.7)

Wiki MarkupThis compliant solution uses the {{Files.delete()}} method from Java 1.7 to delete the file.

Code Block
bgColor#ccccFF

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

Wiki Markup
The Java™ SE 7 Documentation to delete the file. \[[J2SE 2011|AA. Bibliography#J2SE 11]\] defines {{Files.delete()}} to throw the following exceptions:

Exception

Reason

NoSuchFileException

if the file File does not exist

DirectoryNotEmptyException

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

IOException

if an 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

...

...


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

Risk Assessment

Failure to check the return values of methods that perform file I/O can result in unexpected behavior.

...

[API 2006]

File.delete()

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c4574578fd03e337-ac631d93-4b014802-b285b045-79f2f09cd2671636132c45e0"><ac:plain-text-body><![CDATA[

[[J2SE 2011

AA. Bibliography#J2SE 11]]

Files.delete()

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6d9f4601f9143782-d59c89fb-4d0b4b0c-a37e94bb-ee051b978f120a09d3a665ec"><ac:plain-text-body><![CDATA[

[[Seacord 2005a

AA. Bibliography#Seacord 05]]

Chapter 7, "File I/O"

]]></ac:plain-text-body></ac:structured-macro>

...