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.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable