为什么当我在输入文本字段中输入您的名字时出现 4 次“我的名字是”
公共无效比较问题(){
字符串文件名=目录+“memoryBank.txt”;
String line = null;
try {
FileReader fileReader =
new FileReader(fileName);
// Always wrap FileReader in BufferedReader.
BufferedReader bufferedReader =
new BufferedReader(fileReader);
while((line = bufferedReader.readLine()) != null) {
String[] parts = line.split(" - ");
String subject = parts[0];
String question = parts[1];
String answer = parts[2];
//if(input.equals(question) && !subject.equals(currentSubject)){ currentSubject = subject; }
// if(input.equals(question) && subject.equals(currentSubject)){ Output.append(answer); }
if(input.contains("what is your name")) {
Output.append("my name is"+ newline);
}
}
bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
}
}