黑马程序员技术交流社区

标题: 模拟用户登录和文件中存储的用户名、密码匹配 [打印本页]

作者: LARK    时间: 2016-10-19 19:01
标题: 模拟用户登录和文件中存储的用户名、密码匹配
模拟用户登录功能实现。接收用户输入的用户名和密码,然后和文件中存储的用户名、密码匹配
config.txt,中存的内容如下:
userName=admin
passWord=123456

public static void main(String[] args) throws IOException {
                String[] arr = new String[2];
                BufferedReader br = new BufferedReader(new FileReader("config.txt"));
                String[] arr1 = br.readLine().split("=");
                String[] arr2 = br.readLine().split("=");
                br.close();
                User u0 = new User(arr1[1], arr2[1]);
                Scanner sc = new Scanner(System.in);
                while(true){
                        System.out.println("请输入用户名:");
                        String userName = sc.nextLine();
                        System.out.println("请输入密码:");
                        String passWord = sc.nextLine();
                        User u = new User(userName,passWord);
                        if(u.equals(u0)){
                                System.out.println("登陆成功");
                                break;
                        }else{
                                System.out.println("用户名或密码不正确,请重新登陆:");
                        }
                }
        }
}
作者: Kevin_Ye    时间: 2016-10-20 00:09
谢谢分享,支持楼主

作者: LARK    时间: 2016-10-20 14:12
Kevin_Ye 发表于 2016-10-20 00:09
谢谢分享,支持楼主

嗯嗯谢谢一直的关注支持!……

作者: Kevin_Ye    时间: 2016-10-21 01:03
LARK 发表于 2016-10-20 14:12
嗯嗯谢谢一直的关注支持!……







欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2