Read an object
As opposed to reading a text file, we will read an instance of a object.
We'll continue using the MyObject as you probably read in the write an object article.
public MyObject getSavedData(String file) throws
IOException,
ClassNotFoundException{
FileInputStream f_in = new FileInputStream(file);
ObjectInputStream obj_in = new ObjectInputStream (f_in);
Object obj = obj_in.readObject();
obj_in.close();
f_in.close();
return (MyObject)obj;
}
The string file is the absolute path for the file you want to read.
Reading and writing a serialized object is real easy.