Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.FilePermission;
import java.security.AccessControlContext;
import java.security.AccessController;

public class Main extends SecurityManager {

    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.checkPermission(new FilePermission("test.txt", "read,write"), con);

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