passwordsecuritymanager.java
来自「Java样例程序集合:2D」· Java 代码 · 共 49 行
JAVA
49 行
import java.io.*;public class PasswordSecurityManager extends SecurityManager { private String password; public PasswordSecurityManager(String password) { super(); this.password = password; } private boolean accessOK() { int c; DataInputStream in = new DataInputStream(System.in); String response; System.out.println("What's the secret password?"); try { response = in.readLine(); if (response.equals(password)) return true; else return false; } catch (IOException e) { return false; } } public void checkRead(FileDescriptor filedescriptor) { if (!accessOK()) throw new SecurityException("Not a Chance!"); } public void checkRead(String filename) { if (!accessOK()) throw new SecurityException("No Way!"); } public void checkRead(String filename, Object executionContext) { if (!accessOK()) throw new SecurityException("Forget It!"); } public void checkWrite(FileDescriptor filedescriptor) { if (!accessOK()) throw new SecurityException("Not!"); } public void checkWrite(String filename) { if (!accessOK()) throw new SecurityException("Not Even!"); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?