...
Code Block | ||
---|---|---|
| ||
File file = new File("file"); if (!file.delete()) { System.out.println("// Deletion failed");, handle error } |
Compliant Solution
This compliant solution uses the java.nio.file.Files.delete()
method from Java SE 7 to delete the file:
Code Block | ||
---|---|---|
| ||
Path file = new File(args[0]).toPath(); try { Files.delete(file); } catch (IOException x) { System.out.println("// Deletion failed"); // Handle, handle error } |
The Java SE 7 Documentation [J2SE 2011] defines Files.delete()
to throw the following exceptions:
...