英文:
Verifying Multiple users on a Simple Login System
问题
使用.txt文件作为数据库,文件中有两个用户,但此代码只能读取其中一个用户,另一个用户不能读取。我正在尝试使这两个用户都能正常工作。
try {
FileReader fr = new FileReader("C:\\Users\\KIDS\\Desktop\\Marvels\\LoginCred\\Employeelogin.txt");
BufferedReader br = new BufferedReader(fr);
// 读取文本内容
String usernameholder = br.readLine().substring(9);
String passwordholder = br.readLine().substring(9);
if(usernameid.getText().equals(usernameholder) && passwordid.getText().equals(passwordholder)) {
JOptionPane.showMessageDialog(null, "授权访问!");
}
else{
JOptionPane.showMessageDialog(null, "用户名/密码错误");
}
}
catch(Exception e) {
JOptionPane.showMessageDialog(null, "错误");
}
以下是用户信息:
英文:
Im using .txt file as a database and there are 2 users in this file but this code can read only 1 user and the other cannot. im trying that the both of users will work
try {
FileReader fr = new FileReader("C:\\Users\\KIDS\\Desktop\\Marvels\\LoginCred\\Employeelogin.txt");
BufferedReader br = new BufferedReader(fr);
// READS THE TEXT
String usernameholder = br.readLine().substring(9);
String passwordholder = br.readLine().substring(9);
if(usernameid.getText().equals(usernameholder)&& passwordid.getText().equals(passwordholder)) {
JOptionPane.showMessageDialog(null,"Access Granted!");
}
else{
JOptionPane.showMessageDialog(null, "Wrong Username/Password");
}
}
catch(Exception e) {
JOptionPane.showMessageDialog(null,"Error");
}
Here is the Users
enter image description here
专注分享java语言的经验与见解,让所有开发者获益!
评论