入力テキストフィールドにあなたの名前を入力すると、なぜ「私の名前は」と4回表示されるのですか?
public void compareQuestion(){
文字列fileName=ディレクトリ+"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 + "'");
}
}