G
!George Sgouros
Hello everybody!
I am trying to store the instances of my objects to disk.
For the moment I have only managed to write the code which saves an object
to a file, although I am not sure it is correct. Here's the code (executed
just before program termination):
System.out.print(" Saving data to disk...");
File MyDataFile = new File("datafile.txt");
FileOutputStream MyFile = new FileOutputStream(MyDataFile);
ObjectOutputStream MyOutputStream = new ObjectOutputStream(MyFile);
MyOutputStream.writeObject(vehList);
MyFile.close();
System.out.println("done");
where vehList is an instance of class VehicleList which extends the Vector
Java Class
So here are my questions:
1. Is there an easier way to do the above?
2. How can I reconstruct the vehList object when the program initiates?
Many thanks in advance
George
I am trying to store the instances of my objects to disk.
For the moment I have only managed to write the code which saves an object
to a file, although I am not sure it is correct. Here's the code (executed
just before program termination):
System.out.print(" Saving data to disk...");
File MyDataFile = new File("datafile.txt");
FileOutputStream MyFile = new FileOutputStream(MyDataFile);
ObjectOutputStream MyOutputStream = new ObjectOutputStream(MyFile);
MyOutputStream.writeObject(vehList);
MyFile.close();
System.out.println("done");
where vehList is an instance of class VehicleList which extends the Vector
Java Class
So here are my questions:
1. Is there an easier way to do the above?
2. How can I reconstruct the vehList object when the program initiates?
Many thanks in advance
George