file.delete() returns false even though file.exists(), file.canRead(), file.canWrite(), file.canExecute() all return true
It was pretty odd the trick that worked. The thing is when I have previously read the content of the file, I used BufferedReader
. After reading, I closed the buffer.
Meanwhile I switched and now I'm reading the content using FileInputStream
. Also after finishing reading I close the stream. And now it's working.
The problem is I don't have the explanation for this.
I don't know BufferedReader
and FileOutputStream
to be incompatible.
java file.delete() returns false but file.exists() returns true
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.
File.canWrite() returns false after reassignment
@Andreas pointed out that canWrite() returns false if the file does not exist, so I first had to call csvFile.createNewFile()
.
file.canWrite(); file.canRead(); file.canExceute(); always return true though my file/directory had no access rights
You have to check:
SecurityManager.checkDelete(filepath);
As said in the JavaDoc
Related Topics
What's the Difference Between Primitive and Reference Types
Using "Like" Wildcard in Prepared Statement
How to Deploy a War File in Tomcat 7
Unresponsive Keylistener for Jframe
Delete Directories Recursively in Java
How to Parse Date String to Date
How to Ignore Ssl Certificate Errors in Apache Httpclient 4.0
How to Change Jdk Version for an Eclipse Project
Fastest Way to Write Huge Data in Text File Java
"Integer Number Too Large" Error Message for 600851475143
How to Make a Java Thread Wait for Another Thread's Output
Why Is Stringtokenizer Deprecated
How to Specify the Schema When Connecting to Postgres with Jdbc
Eclipse 2021-09 Code Completion Not Showing All Methods and Classes
Iterating Over and Removing from a Map
Filter Invoke Twice When Register as Spring Bean