...
Compliant Solution (Java 1.7)
This compliant solution uses the {{ Wiki Markup Files.delete()
}} method from Java 1.7 to delete the file.
Code Block | ||
---|---|---|
| ||
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 |
---|---|
| if the file File does not exist |
| if the file File is a directory and could not otherwise be deleted because the directory is not empty |
| if an An I/O error occurs |
| In the case of the default provider, and a security manager is installed, the |
...
...
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] | | |||
<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]] | | ]]></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> |
...