public static void main(String[] args) throws IOException, ClassNotFoundException {
String file = "C:\\Users\\RaviKiran Reddy\\Desktop\\JBNR\\NewBankAccounts.csv";
List<String[]> newAccounts = Csv.read(file);
List<Account> opaccounts = new LinkedList<Account>();
for (String[] accountholdersdata : newAccounts) {
String name = accountholdersdata[0];
String ssn = accountholdersdata[1];
String acctype = accountholdersdata[2];
double initialDeposit = Double.parseDouble(accountholdersdata[3]);
if (acctype == "Checking") {
opaccounts.add(new Checking(name, ssn, acctype, initialDeposit));
}
else {
opaccounts.add(new Savings(name, ssn, acctype, initialDeposit));
}
}
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("records.txt"));
out.writeObject(opaccounts);
ObjectInputStream in = new ObjectInputStream(new FileInputStream("records.txt"));
LinkedList<Account> a = new LinkedList<Account>();
a = (LinkedList<Account>) in.readObject();
}
I wanted to build a real world bank application, so I stored the objects in a ".txt" file with the help of LinkedList
and ObjectOutputStream
. But the problem is whenever I perform operations on a object and close the project, and after when I again open the project and try to retrieve the data, the data regarding the previous operations is not being stored.
How to overcome this and store each and every operation performed on the objects?