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