...
Noncompliant Code Example (delete()
)
This noncompliant code example attempts to delete a specified file but gives no indication of its success. The Java Platform, Standard Edition 6 API Specification \[ [API 2006|AA. References#API 06] \] requires {{ Wiki Markup File.delete()
}} to throw a {{SecurityException
}} only when the program lacks authorization to delete the file. No other exceptions are thrown, so the deletion can silently fail.
Code Block | ||
---|---|---|
| ||
File file = new File(args[0]); file.delete(); |
...
Code Block | ||
---|---|---|
| ||
Path file = new File(args[0]).toPath(); try { Files.delete(file); } catch (IOException x) { System.out.println("Deletion failed"); // handle error } |
The Java SE 7 Documentation \[ [J2SE 2011|AA. References#J2SE 11]\] defines {{ Wiki Markup Files.delete()
}} to throw the following exceptions:
Exception | Reason |
---|---|
| File does not exist |
| File is a directory and could not otherwise be deleted because the directory is not empty |
| An I/O error occurs |
| In the case of the default provider and a security manager is installed, the |
...
Bibliography
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="523ec875-257b-4f07-9d7f-3a4499210240"><ac:plain-text-body><! [CDATA[ [[API 2006AA. References#API 06] ] | | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="40eb997d-a58f-428f-ae5a-14c11d5caa02"><ac:plain-text-body><! [CDATA[ [[J2SE 2011AA. References#J2SE 11] ] |
| |
[ [[Seacord 2005AA. References#Seacord 05]] | Chapter 7, File I/O ]]></ac:plain-text-body></ac:structured-macro> |
...