如果特定数据位于文本文件中,如何创建仅继续的程序。是否可以使用BufferedReader/FileReader
来读取和搜索每一行,直到找到来自用户的匹配输入数据。假设我创建了一个登录表单,文本文件中的数据将是:
username;password
username1;password1
所以在这里我对if语句很困惑,如何才能读取文本文件中的每一行,直到找到正确的匹配并允许用户进入下一帧?
答案 0 :(得分:2)
如果我正确阅读此内容,请尝试以下操作:
List<String> credentials = new ArrayList<>();
// Populate this list with all of your credentials
BufferedReader bReader = new BufferedReader(new FileReader(textFile));
boolean foundCredentials = false;
String line;
while ((line = bReader.readLine()) != null) {
// Set your condition to analyze the line and find the credentials you are looking for
if (credentials.contains(line)) {
foundCredentials = true;
break;
}
}
bReader.close();
if (foundCredentials) {
// Proceed to next frame
}