我有一个文件叫“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先生的记录,我更新了新的信用卡类型和号码。这是为什么发生?我在try语句中做了System.out.println(text)
,并且都正确地打印出来了。任何人都可以帮忙
你写了一个未加密的信用卡号的纯文本文件? – LittleBobbyTables 2013-04-29 11:45:39
@LittleBobbyTables看看信用卡号码,我认为OP是学习文件处理,这只是一个测试项目 – Apurv 2013-04-29 11:47:01
是它的测试项目。没有其他的。为什么那么认真? – John 2013-04-29 11:47:37