java - How to delete an object that are written into file? -
in program, user gives inputs , added arraylist. arraylist object written file. have created method writing , read file (using file-i/o & object-i/o stream).
now if want delete particular object file, how do that?
this part of workin on:
case 4: bankaccounts2=(list<bankaccount>)rw.readfromfile();//method calling; bankaccount class settre , getter iterator<bankaccount> it=bankaccounts2.iterator();//bankaccounts2 arraylist reading file system.out.println("enter account want delete:"); deleteacc = sc.nextint(); while (it.hasnext()) { bankaccount next = it.next(); if (next.getaccnum() == deleteacc) { it.remove(); } } break;
the easiest solution in mind read objects file arraylist
. remove 1 want delete aforementioned list. finally, overwrite initial contents of file new contents in list.
if not want re-read contents of file , have reference list of objects in memory, can remove object , overwrite contents of file
Comments
Post a Comment