Java.util.PropertyPermission.implies()


描述

所述java.util.PropertyPermission.implies(Permission p)的方法检查PropertyPermission意味着指定的权限。这是通过检查做p是PropertyPermission对象是否,动作p是此对象的操作的一个子集,如果这个对象的名字所暗示的普的行动。

声明

以下是java.util.PropertyPermission.implies()方法的声明

public boolean implies(Permission p)

参数

p - 要检查的Permission对象。

返回值

如果此对象隐含指定的Permission,则此方法返回true。

异常

NA

实例

以下示例显示了java.util.PropertyPermission.implies(Permission)方法的用法。

package com.tutorialspoint;

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