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

One thought on “Java IO – Read and Write Java Objects

  • February 11, 2017 at 1:31 pm
    Permalink

    thank you for your example.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.