In my program I need to update the Balance column of the text file each time the user does a withdrawal. I used both the write methods as well as the append methods, but to no avail. Once the user has logged in, that particular line is stored in the array
#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
The code:
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();
}