File file = new File(path);
if (!file.delete())
{
throw new IOException(
\"Failed to delete the file because: \" +
getReasonForFileDeletionFailur
Java 7 java.nio.file.Files class can be also used:
http://docs.oracle.com/javase/tutorial/essential/io/delete.html
try {
Files.delete(path);
} catch (NoSuchFileException x) {
System.err.format("%s: no such" + " file or directory%n", path);
} catch (DirectoryNotEmptyException x) {
System.err.format("%s not empty%n", path);
} catch (IOException x) {
// File permission problems are caught here.
System.err.println(x);
}