我有一个名为“CI.txt”的文件
文件里面的信息是:
Mr Abc;ABC;abc123;Abc Road;428428;VISA;2222111144442222
Mr Efg;EFG;efg123;Efg Road;424213;MASTERCARD;4444555566667777
Mr Lmn;LMN;lmn123;Lmn Road;492482;VISA;9999000011112222
这是我的代码,它工作得很好,但问题是..
for (Customer ci : custList){
//Compares the username and userpassword
//If correct, set new card number and card type..
if (inputUser.equals(ci.getUserName()) && inputPass.equals(ci.getPassword())) {
ci.setCardNo(newCardNo);
ci.setCardType(newCardType);
}
String text = ci.getRealName() + ";" + ci.getUserName() + ";" + ci.getPassword() + ";" + ci.getContact() + ";" + ci.getcardType() + ";" + ci.getcardNo();
try {
File fileCI = new File("CI.txt");
FileWriter fileWriter = new FileWriter(fileCI);
BufferedWriter bw = new BufferedWriter(fileWriter);
bw.write(text);
bw.close();
}
catch (FileNotFoundException e) {
System.out.println("File not found");
}
catch (IOException e) {
System.out.println("Unable to write to file");
}
}
我的输出将只有 Lmn 先生的记录。没有我更新新信用卡类型和号码的 Abc 先生的记录。为什么会这样?我System.out.println(text)
在 try 语句中做了,一切都被正确打印出来了。任何人都可以帮忙吗?