Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
We use java.io.ObjectOutputStream and ObjectInputStream .
Wrap FileOutputStream in the ObjectOutputStream.
Make a client instance.
Write it to the file.
Open for reading.
Read the first one.
Cast to Client,....
so we can access its data.
Any class that implements Serializable can be streamed this way,....
as long as it contains Serializable data.
All fundamental data types are serializable :
byte, short, int, long
And most classes in the Java library are Serializable, too, like String.
Implementing the java.io.Serializable interface does not imply that methods have to be defined, because there are none in the interface, it's empty.
Storing different classes in one file is possible, but not such a good idea, because it brings a lot of overhead to the file.