File file = new File(path); if (!file.delete()) { throw new IOException( \"Failed to delete the file because: \" + getReasonForFileDeletionFailur
Be aware that it can be your own application that prevents a file from being deleted!
If you wrote to the file previously and didn't close the writer, you are locking the file yourself.