码迷,mamicode.com
首页 > 其他好文 > 详细

SecurityManager USE

时间:2018-04-24 13:57:47      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:edr   value   --   red   port   his   密码   lin   mission   

 

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class BaseT {

    public static void main(String[] args) throws IOException {
        
        System.setSecurityManager(new mySecurityM("ABC","123"));
        File f=new File("E:\\Test.java"); 
        DataInputStream fis=new DataInputStream(new FileInputStream(f));
        String x="";
        
        while((x=fis.readLine())!=null){
            System.out.println(x);
        }
        fis.close();
    }
}

//----------------------
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class mySecurityM extends SecurityManager {
    private String upwd;
    private String unam;
    public mySecurityM(String unam,String upwd){
        this.upwd=upwd;
        this.unam=unam;
    }
    public boolean okacess(){
        System.out.println("请输入用户名和密码,用逗号隔开");
        BufferedReader dis = new BufferedReader(new InputStreamReader(System.in));
        try {
        String[] value=dis.readLine().split(",");
        if (value[0].equals(this.unam)&&value[1].equals(this.upwd))
        return true;
        else
        return false;
        } catch (IOException e) {
        return false;
        }
    }
 
    public void checkRead(String file){
        if(!okacess()){
            throw new SecurityException("No Premission.");
        }
    }
    
}

 

SecurityManager USE

标签:edr   value   --   red   port   his   密码   lin   mission   

原文地址:https://www.cnblogs.com/rojas/p/8929134.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!