Use AccessController . You can wrap all calls in a block AccessController.doPrivileged.
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
...
return null;
}
});
, , , , :
Boolean flag = AccessController.doPrivileged(new PrivilegedAction() {
public Boolean run() {
boolean flag = false;
// privileged code goes here, for example, read and writing files. If it succeeds, set flag to true.
...
return flag; // return true, if the privileged action succeeded
}
});
. , ; " " , .
AccessControlException s, . , , , false. AccessController.doPrivilege .
# 2
AccessController.checkPermission , . , , .