Java Create an ObjectInputStream

Java Create an ObjectInputStream

To create an ObjectInputStream in Java, you can use the following code:

ObjectInputStream ois = new ObjectInputStream(new FileInputStream("data.bin"));
Source‮ww:‬w.lautturi.com

This creates a new ObjectInputStream called ois that reads from the file "data.bin". The ObjectInputStream is a class that allows you to read objects from an input stream.

To read an object from the ObjectInputStream, you can use the readObject method, like this:

Object obj = ois.readObject();

This reads an object from the ObjectInputStream and stores it in the obj variable.

It is important to remember to close the ObjectInputStream when you are finished reading from it, to release any resources that it is using. You can do this using the close method, like this:

ois.close();
Created Time:2017-11-03 00:14:39  Author:lautturi