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

Writing Binary Data

DataOutputStream out =
											new DataOutputStream(socket.getOutputStream());
											out.write(byteArray, 0, 10);

In a previous phrase in this chapter, “Writing Text,” we showed how to write text data across a network. In this phrase, we show how to write binary data across a network. This phrase assumes that we’ve previously created a socket to the server from which we want to write text. See the phrase “Contacting a Server” in this chapter for more details on creating the socket instance.

In this phrase, we call the getOutputStream() method of the socket instance to obtain a reference to the socket’s output stream. We then instantiate a DataOutputStream, which we can use to write binary data across the network. We use the write() method ...

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