An example of how to serialize an object:
public static void writeToFile(File path, Database data)
{
try(ObjectOutputStream write= new ObjectOutputStream (new FileOutputStream(path)))
{
write.writeObject(data);
}
catch(NotSerializableException nse)
{
//do something
}
catch(IOException eio)
{
//do something
}
}
public static Object readFromFile(File path)
{
Object data = null;
try(ObjectInputStream inFile = new ObjectInputStream(new FileInputStream(path)))
{
data = inFile.readObject();
return data;
}
catch(ClassNotFoundException cnfe)
{
//do something
}
catch(FileNotFoundException fnfe)
{
//do something
}
catch(IOException e)
{
//do something
}
return data;
}
For more info http://docs.oracle.com/javase/tutorial/jndi/objects/serial.html