java file.delete() returns false but file.exists() returns true
delete-file, file, java
Solution
When I am trying to delete a file which is present in tomcat server conf/Catalina/localhost from java code then file.delete() always returns false. But if i am checking the file by file.exists() function it returns true.
Most likely you do not have permission for deleting file(s) on Server. Check your permissions.
`f.delete()` returns false it means that it wasn't / could not be deleted and `f.exists()` returns true so file exists but cannot be deleted.
Problem
When I am trying to delete a file which is present in tomcat server conf/Catalina/localhost from java code then file.delete() always returns false. But if I am checking the file by file.exists() function it returns true. I am not getting any exception. Please help us why this is happening. What is the solution for this?