【发布时间】:2016-09-07 21:35:39
【问题描述】:
我有一个程序,用户名和密码在一个文本文件中,文本文件如下所示:
election:12345
我有这段代码可以读取文件
try {
BufferedReader read=new BufferedReader(new FileReader("election_un_pass.txt"));
String line="";
while((line=read.readLine())!=null) {
String [] info=line.split(":");
if(info[0].matches(Login.uname) && info[1].matches(Login.pass)){
new Main();
} else {
JOptionPane.showMessageDialog(null, "Username or Password might not be correct");
}
Login.txtUName.setText("");
Login.txtPassword.setText("");
}
} catch (Exception e1) {
e1.printStackTrace();
}
每次我运行我的程序时,即使我输入的用户名和密码是正确的,Username or Password might not be correct 消息仍然会出现,new Main() 不会出现。
【问题讨论】:
-
请检查 Login.uname 和 Login.pass 值似乎它们不匹配。
-
确定不想使用
String.equals?Login的值是多少? -
@VuralAcar 哦,它们实际上是匹配的,并且 Login.uname 和 Login.pass 被初始化为 txtUName.getText() 和 txtPassword.getText() 但由于你的建议,我只是直接使用了 txtUName .getText() 和 txtPassword.getText()。非常感谢!!!!
-
@Marvin
txtUName.getText()和txtPassword.getText()但我现在只是直接使用它们,现在已经修复了,非常感谢!!!
标签: java file oop bufferedreader