在我的程序中,我需要在每次用户进行提款时更新文本文件的余额列。我同时使用了写入方法和附加方法,但无济于事。 一旦用户已登录,则该特定行被存储在数组中在java中更新文本文件的特定部分
#PIN AccountNo Balance
1598 01-10-102203-0 95000
4895 01-10-102248-0 45000
9512 01-10-102215-0 125000
6125 01-10-102248 85000
的代码:
try{
BufferedWriter out = new BufferedWriter(new FileWriter(".\\AccountInfo.txt",true));
if (amount <= 0.0) {
System.out.println("can only withdraw positive amount!");
transactionScreen();
}
else if (this.balance >= amount) {
if(amount>15000.0){
System.out.println("The maximum amount allowed per transaction is only Rs.15000/=");
transactionScreen();
}
else{
this.balance -= amount;
object.c=this.balance;
String newBal=Double.toString(this.balance);
out.write("");
//out.append("");
out.write(newBal);
//out.append(newBal);
}
}
else {
System.out.println("not enough money in account!");
transactionScreen();
}
}
catch(IOException e){
e.printStackTrace();
}
+1 - 为提示(正确地)数据库将是一个更好的主意。 – 2010-10-03 09:38:53
我可以使用数据库,但不幸的是我需要仅使用记事本文件来完成此程序。所以,如果你可以,你可以给我的代码,我可以重新写整个文件的所有优势。谢谢 – Yoosuf 2010-10-03 09:39:56
@Yoosuf:为什么你不能使用数据库?如果您需要将输出作为文本文件,则可以将其作为文本文件从数据库中导出。正如我所说,为什么不应该为此使用文本文件有很多原因,那么需求来自哪里呢?作为一名程序员,您有责任向您的客户指出他们的解决方案存在问题 - 特别是当它是账户余额等信息时。或者这是作业吗?那么我认为你应该问一些使用什么方法的提示,而不是要求我们为你写代码。 – 2010-10-03 09:44:04