|
How do I save an array list of serialized objects?
|
Posted: Sep 11, 2003 7:48 PM
|
|
Advertisement
|
I currently trying this approach, because a more straightforward one keeps failing. A file is created, but no data is ever retrieved:
The save:
private void SaveCustomerData() {
// customerDataList is the ArrayList // used to save customer data to disk
try {
ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream(FILE_NAME)); for(int i=0;i<customerDataList.size();i++) { CustomerData customerDataItem=(CustomerData) customerDataList.get(i); out.writeObject(customerDataItem); }
out.close();
}
catch(Exception e) {
}
}
The load:
private void GetCustomerDataFromDisk() {
// used to retrieve customer data from disk
boolean errorTriggered=false;
try {
ObjectInputStream in=new ObjectInputStream(new FileInputStream(FILE_NAME)); CustomerData[] customerDataItems=(CustomerData[]) in.readObject(); for(int i=0;i<customerDataItems.length;i++) AddCustomerFromDisk(customerDataItems.getCustomerFirstName(),customerDataItems.getCustomerLastName(),customerDataItems.getCustomerID(),customerDataItems.ge tSavingsAccount(),customerDataItems.getCheckingAccount(),customerDataItems.get InvestmentAccount(),customerDataItems.getLineOfCreditAccount());
in.close();
}
...
etc.
}
|
|