O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading Serialized Data

ObjectInputStream in =
											new ObjectInputStream(socket.getInputStream());
											Object o = in.readObject();

Java enables object instances to be serialized and written either to a file or across a network. In this phrase, we show how you can read from a network socket an object that has been serialized. This phrase assumes that we’ve previously created a socket to the server with which we want to communicate. See the phrase “Contacting a Server” in this chapter for more details on creating the socket instance.

In this phrase, we call the getInputStream() method of the socket instance to get a reference to the socket’s input stream. Using this, we can instantiate an ObjectInputStream instance. The ObjectInputStream class is used ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required