Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file.canWrite(); file.canRead(); file.canExceute(); always return true though my file/directory had no access rights

Tags:

java

windows

need to check permission of file/directory i used

 //filePath = path of file/directory access denied by user ( in windows )
 File file = new File(filePath);
 file.canWrite(); 
 file.canRead();
 file.canExecute();

all of three returns true but m not able to delete any file/directory

like image 741
Pravin Avatar asked Oct 22 '22 14:10

Pravin


2 Answers

You have to check:

SecurityManager.checkDelete(filepath);

As said in the JavaDoc

like image 95
Michaël Avatar answered Oct 27 '22 11:10

Michaël


Have you tried using the java.nio.file.Files#isWritable method?

like image 33
racc Avatar answered Oct 27 '22 10:10

racc