public void checkPermissionUsingAccessController(String path)
{
try
{
AccessController.checkPermission(new FilePermission(path, "write"));
System.out.println("Passed");
}
catch(SecurityException e)
{
System.out.println("Sorry no rights");
}
}
public static void main(String[] args)
{
UserPrivileges userPrivileges = new UserPrivileges();
userPrivileges.checkPermissionUsingAccessController(System.getProperty("user.dir"));
PropertiesExample example = new PropertiesExample();
example.saveProperties("example");
System.out.println(System.getProperty("user.dir"));
}
打印:Sorry no rights
当我运行这个程序时,即使AccessController告诉该应用程序没有写入权限,我仍然可以写入pwd。谁能告诉我哪里错了?