我有一个程序,用户名和密码是一个文本文件,该文本文件看起来像这样:的BufferedReader将无法读取
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'? “登录”的价值是什么? – Marvin
@VuralAcar哦,他们实际上是匹配的,Login.uname和Login.pass被初始化为txtUName.getText()和txtPassword.getText(),但由于你的建议,我直接使用了txtUName.getText()和txtPassword。 gettext的()。非常感谢!!!! – luh