如何在java中使用txt文件进行登录

时间:2015-05-09 03:31:17

标签: java java.util.scanner

我正在尝试使用txt文件开发登录我的问题是在if (Authenticator.equals(un+" "+pw))它没有通过true并且正在转移到我的else语句。为什么我的陈述不正确?我知道它只检查第一行.....建议任何人? what I have in the note pad and the printed results

private void SubmitActionPerformed(java.awt.event.ActionEvent evt) {                                       
                String un = UserName.getText().trim();
                String pw = Password.getText().trim();
            try {
                Scanner Scan = new Scanner(new File("Login.txt"));            
                System.out.println(Scan.nextLine().trim());
                String Authenticator = Scan.nextLine().trim();
                    if (Authenticator.equals(un+" "+pw)){
                    System.out.println("sweetness");
                    } else {
                        System.out.println("bummer");
                    }
                }catch (Exception ex) {
                    ex.printStackTrace();
                }
            System.out.println(un+" "+pw);                 
        }

0 个答案:

没有答案
相关问题