其他
Java教程-Java FilePermission类
整理:Java面试那些事儿
D:\IO-:表示权限递归地与所有子目录和文件关联。 D:\IO*:表示权限与该目录中的所有目录和文件关联,但不包括子目录。
Java FilePermission类声明
让我们看一下Java.io.FilePermission类的声明:
public final class FilePermission extends Permission implements Serializable
专属福利
Method | Description |
Java FilePermission类方法
Method | Description |
Java FilePermission示例
package cn.javatiku;
import java.io.*;
import java.security.PermissionCollection;
public class FilePermissionExample{
public static void main(String[] args) throws IOException {
String srg = "D:\\IO Package\\java.txt";
FilePermission file1 = new FilePermission("D:\\IO Package\\-", "read");
PermissionCollection permission = file1.newPermissionCollection();
permission.add(file1);
FilePermission file2 = new FilePermission(srg, "write");
permission.add(file2);
if(permission.implies(new FilePermission(srg, "read,write"))) {
System.out.println("Read, Write permission is granted for the path "+srg );
}else {
System.out.println("No Read, Write permission is granted for the path "+srg); }
}
}
Read, Write permission is granted for the path D:\IO Package\java.txt
我就知道你会点赞+“在看”