In my program, user gives some inputs and those are added into an arrayList. The arrayList object are written into file. Thus I have a created method for writing into and read from file (using file-i/o & object-i/o stream).
Now If I want to delete a particular object from the file, how do I do that?
This is the part of I am workin on:
case 4:
bankAccounts2=(List<BankAccount>)rw.readFromFile();//method calling; BankAccount is the class for settre and getter
Iterator<BankAccount> it=bankAccounts2.iterator();//bankAccounts2 is the arrayList for reading file
System.out.println("Enter the account you want to delete:");
deleteAcc = sc.nextInt();
while (it.hasNext()) {
BankAccount next = it.next();
if (next.getAccNum() == deleteAcc) {
it.remove();
}
}
break;