Example usage for java.lang SecurityManager checkRead

List of usage examples for java.lang SecurityManager checkRead

Introduction

In this page you can find the example usage for java.lang SecurityManager checkRead.

Prototype

public void checkRead(String file, Object context) 

Source Link

Document

Throws a SecurityException if the specified security context is not allowed to read the file specified by the string argument.

Usage

From source file:Main.java

public static void main(String[] args) {
    AccessControlContext con = AccessController.getContext();

    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    sm.checkRead("test.txt", con);

    System.out.println("Allowed!");
}