java.util.PropertyPermission.implies()方法实例
java.util.PropertyPermission.implies(Permission p) 如果这PropertyPermission暗示指定的权限方法检查。这是通过检查PropertyPermission对象,对动作p是该对象的动作子集,如果这个对象的名字所暗示p的操作。
声明
以下是java.util.PropertyPermission.implies()方法的声明
public boolean implies(Permission p)
参数
-
p -- 检查的权限对象。
返回值
如果此对象暗示指定的权限,此方法返回true。
异常
NA例子
下面的示例演示java.util.PropertyPermission.implies(Permission)方法的用法。
package com.yiibai; import java.util.PropertyPermission; public class PropertyPermissionDemo { private static PropertyPermission permission; public static void main(String[] args) { // Create property permission object permission = new PropertyPermission("java.*", "read,write"); // Check permissions checkFileReadPermission("java.home"); checkFileWritePermission("java.home"); } private static void checkFileReadPermission(String path) { // Check permission on read action if(permission.implies(new PropertyPermission(path, "read"))) { System.out.println("Has permissions on "+path+" for read"); } } private static void checkFileWritePermission(String path) { // Check permission on read action if(permission.implies(new PropertyPermission(path, "write"))) { System.out.println("Has permissions on "+path+" for write"); } } }
让我们来编译和运行上面的程序,这将产生以下结果:
Has permissions on java.home for read Has permissions on java.home for write