Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com

Essence OUT.

Essence IN.

We use java.io.ObjectOutputStream and ObjectInputStream .

Wrap FileOutputStream in the ObjectOutputStream.

Make a client instance.

Write it to the file.

Another one.

Open for reading.

Read the first one.

Cast to Client,....

so we can access its data.

Next one.

===========

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
float, double
char
boolean

And most classes in the Java library are Serializable, too, like String.

=========

NOTES

=========

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.

.