Java IO – Read and Write Java Objects

Introduction

ObjectInputStream can be used to de-serialize and read java objects that have been serialized and written using ObjectOutputStream. In the example below the ‘Course’ object is written to a persistent storage. The Course object contains a list of Student objects. The object writing preserves object references. We first create an object output stream that stores the bytes to a file using a FileOutputStream.

The Course Class

The Student Class

1 thought on “Java IO – Read and Write Java Objects”

Leave a Comment