File.Delete() Returns False Even Though File.Exists(), File.Canread(), File.Canwrite(), File.Canexecute() All Return True

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



Leave a reply



Submit