Reputation: 29
I am trying to delete a file: This is the code and I can't see anything wrong
System.out.println("users//"+"user"+i.getId());
File f=new File("users//"+"user"+i.getId());
System.out.println("Can READ: "+f.canRead());
System.out.println("Can WRITE: "+f.canWrite());
System.out.println("Can EXEC: "+f.canExecute());
System.out.println("Exists: "+f.exists());
System.out.println(f.delete());
Yes, I have the right to read,write,exec and the file exists. I don't have any exceptions
Upvotes: 1
Views: 644
Reputation: 24157
I have tried this code and it works:
public static void main(String[] args) {
try {
File file = new File("c:\\Users\\Akhil\\logfile11052015.log");
if (file.delete()) {
System.out.println("Success: " + file.getName() + " is deleted!");
} else {
System.out.println("Failed: Delete operation is failed.");
}
} catch (Exception e) {
e.printStackTrace();
}
}
May be you can check if you are providing correct path in your case and file exists there.
Output: Success: logfile11052015.log is deleted!
Upvotes: 3