button - 扫描仪不会继续读取多行文件进行登录功能
问题描述
我有一个登录按钮,它从 text.file 读取两行文本,第一行是用户名,第二行是密码。文本文件中有多个用户名和密码,但该代码仅适用于第一对。
btLogin.setOnAction(e -> {
boolean grantAccess = false;
String userName = tfUsername.getText();
String password = tfPassword.getText();
File f = new File("users.txt");
try {
Scanner read = new Scanner(f);
int lineNo=0;
while(read.hasNextLine()) {
lineNo++;
String loginInfo = read.nextLine();
if ((lineNo == 1)&& (loginInfo.equals(userName))) {
continue;
}
else if ((lineNo == 2) && (loginInfo.equals(password))) {
grantAccess=true;
break;
}
else {
break;
}
}
解决方案
推荐阅读
- xamarin.forms - Xamarin Forms IsEnabled MultiTrigger on Entry 不起作用
- xamarin - Xamarin.Forms UWP 中不显示条目文本
- nativescript - Nativescript Vue ListPicker 不更新它的项目
- r - as.factor 不适用于 R 上的 INT 值
- multithreading - 创建更多线程并同时运行它们会增加进程的 CPU 时间吗?
- python - TensorFlow 和 Keras 中的度量系统行为
- javascript - 当 excel 文件触发动作时运行 JavaScript 脚本
- osquery - osquery如何运行select命令?
- c# - 根据 WPF 中的布尔值用恢复替换删除按钮
- netsuite - 如何在 SuiteScript 2.0 中获取 recordRef?