I have three class as boat,car,truck etc who extend from vehicle , I write all the object of this in a file say vehicleOrder.dat like this :
fout = new FileOutputStream("VehicleOrders.dat");
oos = new ObjectOutputStream(fout);
oos.writeObject(v); //where v is object of boat,truck car etc
Till here its good ,it writes, but when I try to read the dat file like this,
fin = new FileInputStream("VehicleOrders.dat");
ois = new ObjectInputStream(fin);
vehicle readInstance=null;
do{
readInstance = (vehicle)ois.readObject();
if(readInstance != null)
{
orderList.add(readInstance);
}
}
while (readInstance != null);
it reads the two objects which are in the dat file but after that goes to the do again and gives null pointer exception