Java SecurityManager .checkRead (String file, Object context)
Syntax
SecurityManager.checkRead(String file, Object context) has the following syntax.
public void checkRead(String file, Object context)
Example
In the following code shows how to use SecurityManager.checkRead(String file, Object context) method.
import java.security.AccessControlContext;
import java.security.AccessController;
/* w ww .j a v a 2s .com*/
public class Main extends SecurityManager {
public static void main(String[] args) {
AccessControlContext con = AccessController.getContext();
System.setProperty("java.security.policy", "file:/C:/java.policy");
Main sm = new Main();
System.setSecurityManager(sm);
sm.checkRead("test.txt", con);
System.out.println("Allowed!");
}
}
The code above generates the following result.