オブジェクト出力ストリームを使用して自分で書き込んだファイルを読み込もうとしています。これは私がそれを書く方法です:
try
{
fout = new FileOutputStream("VehicleOrders.dat");
oos = new ObjectOutputStream(fout);
for(vehicle v:orderList) ///Travesing to array collection of vehicles and typecasting to repective child object then calling individual methods
{
oos.writeObject(v); //Here I have checked 'v' isproperly initialized and has the required properties assigned too
}
}
この後、ファイルにいくつかのデータを書き込みます。「v」の詳細をバイエレブします
次に、次のように同じファイルを読み取ろうとしました。
fin = new FileInputStream("VehicleOrders.dat"); //this is the same file,
ois = new ObjectInputStream(fin);
vehicle readInstance=null;
while (orderCount>0) //here order count is number of objects in the file kind of meta data
{
readInstance = (vehicle)ois.readObject(); //here 'readInstance' object is set to right object class i.e car but all the properties for some reason are set to null!!!!
if(readInstance != null)
{
orderList.add(readInstance); //read instance is not null ,it has car object but its values are set to zero :(
}
orderCount--;
}
ois.close();
//as u see I can't read it properly,I believe this is because one of these reasons or other:
Maybe the file is not written properly,but I check object v before writing,it is proper
maybe because it has to do some thing with the class it uses and its constructors i.e vehicle and Car which extends vehicle
May be some other reason I am not aware of