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 Binary Data

DataInputStream in =
											new DataInputStream(socket.getInputStream());
											in.readUnsignedByte();

In this phrase, we show how to read binary data across a network. This phrase assumes that we’ve previously created a socket to the server from which we want to read text. 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 obtain a reference to the socket’s input stream. Passing the input stream as a parameter, we instantiate a DataInputStream, which we can use to read binary data across the network. We use the readUnsignedByte() method to read a single unsigned byte across the network.

If the volume of data ...

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