Java.util.PropertyPermission.equals() 方法


Java.util.PropertyPermission.equals() 方法

package com.codingdict;

import java.util.PropertyPermission;

public class PropertyPermissionDemo {
   private static PropertyPermission permission;

   public static void main(String[] args) {

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

      // Check file read permissions
      checkFileReadPermissions("java.home.usr");

      // Check file write permissions
      checkFileWritePermissions("java.home.usr");
   }

   private static void checkFileReadPermissions(String path) {

      // Check permissions are equal
      if(permission.equals(new PropertyPermission(path, "read"))) {
         System.out.println("Has permissions on "+path+" for read");
      }
   }

   private static void checkFileWritePermissions(String path) {

      // Check permissions are equal
      if(permission.equals(new PropertyPermission(path, "write"))) {
         System.out.println("Has permissions on "+path+" for write");
      }
   }
}