Java.util.PropertyPermission.getActions()


描述

在java.util.PropertyPermission.getActions()方法返回字符串表示本动作的列表(e.g. "read,write")。

声明

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

public String getActions()

参数

NA

返回值

此方法返回操作的字符串表示形式(例如“read,write”)。

异常

NA

实例

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

package com.tutorialspoint;

import java.util.PropertyPermission;

public class PropertyPermissionDemo {
   private static PropertyPermission permission;

   public static void main(String[] args) {

      // Build property permissions
      permission = new PropertyPermission("java.home.*", "read,write");

      // Check permissions
      checkFilePermissions("java.home.usr");
   }

   private static void checkFilePermissions(String path) {

      // Check permission given name
      if(path.matches(permission.getName())) {

         // Get actions list
         String actions = permission.getActions();

         // Match read write actions
         if(actions.contains("read"))
         System.out.println("Has permissions on "+path+" for read");

         if(actions.contains("write"))
         System.out.println("Has permissions on "+path+" for write");
      }
   }
}

让我们编译并运行上面的程序,这将产生以下结果

Has permissions on java.home.usr for read
Has permissions on java.home.usr for write