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 ...

Get Java™ Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.