I give you a sample
import java.io.Serializable; public class Account implements Serializable { private int accountNo; private String custName; private int balance; public Account(int accNo, String name, int bal) { this.accountNo = accNo; this.custName = name; this.balance = bal; } @Override public String toString() { String str = "Account No:" + this.accountNo; str += "\nCustomer name:" + this.custName; str += "\nBalance:" + this.balance; return str; } }
Writing and reading an object
package me.dev; import java.io.EOFException; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; public class Main { public void writeObject(ArrayList<Object> listAccount) throws IOException {
source share