5

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

Pravin
  • 1,137
  • 12
  • 20

2 Answers2

2

You have to check:

SecurityManager.checkDelete(filepath);

As said in the JavaDoc

Michaël
  • 3,679
  • 7
  • 39
  • 64
  • `securityManager.checkDelete(fileLocaton);` gives me `java.lang.NullPointerException` Exception rather then SecurityException – Pravin Mar 21 '13 at 10:55
  • though `File file = new File(fileLoction)` and `file.exist();` returns true – Pravin Mar 21 '13 at 11:03
1

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

racc
  • 1,222
  • 10
  • 13
  • Why the downvote? Files.isWritable worked for me on Windows where the user is denied write access to the file, and File.canWrite returns true. System.getSecurityManager was returning null also. – racc Jan 03 '14 at 02:30