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 Text

BufferedReader in =
											new BufferedReader(new InputStreamReader(
											socket.getInputStream()));
											String text = in.readLine();

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. Given the socket instance, we call the getInputStream() method to get a reference to the socket’s input stream. With that, we create an InputStreamReader and use it to instantiate a BufferedReader for reading in the text across the network. The readLine() method of the BufferedReader.

Using the BufferedReader as we do in this phrase allows for efficient reading of characters, arrays, and lines. If we were interested ...

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