How do you check if the application has permission to read or write to specific directories on the filesystem. I am trying this:
try {
AccessController.checkPermission(new FilePermission(files[i]
.getAbsolutePath(), "read,write"));
}
catch (Exception e) {
System.out.println(e.toString());
}
but it always throws the exception and outputs:
java.security.AccessControlException: access denied ("java.io.FilePermission" "C:\Dell" "read")
java.security.AccessControlException: access denied ("java.io.FilePermission" "C:\Documents and Settings" "read")
java.security.AccessControlException: access denied ("java.io.FilePermission" "C:\glut-3.7.6" "read")
Is there something I'm missing here?
Seems that AccessController always throws an exception when you don't have permission. You can handle this by catching SecurityException.
Better solution to check read/write permission with java.io.File.canRead(), java.io.File.canWrite() methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With