例子
以下示例显示java.io.FilePermission.implies(Permission p)方法的用法。
package com.jc2182;
import java.io.FilePermission;
import java.io.IOException;
public class FilePermissionDemo {
public static void main(String[] args) throws IOException {
FilePermission fp = null;
FilePermission fp1 = null;
FilePermission fp2 = null;
FilePermission fp3 = null;
boolean bool = false;
try {
// create new file permissions
fp = new FilePermission("C://test.txt", "read");
fp1 = new FilePermission("C://test.txt", "write");
fp2 = new FilePermission("C://test1.txt", "read");
fp3 = new FilePermission("C://test.txt", "read");
// tests if implied by this object
bool = fp.implies(fp1);
// print
System.out.println(bool);
bool = fp.implies(fp2);
System.out.println(bool);
bool = fp.implies(fp3);
System.out.print(bool);
} catch(Exception ex) {
// if an error occurs
ex.printStackTrace();
}
}
}
让我们编译并运行以上程序,这将产生以下结果-