java.util.PropertyPermission.getActions()方法實例
java.util.PropertyPermission.getActions() 方法返回當前操作的列表中的字符串表示形式(如“read,write”)。
聲明
以下是java.util.PropertyPermission.getActions()方法的聲明
public String getActions()
參數
NA返回值
此方法返回操作的字符串表示形式(如“read,write”)。
異常
NA例子
下麵的例子顯示java.util.PropertyPermission.getActions()方法的用法。
package com.yiibai; 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