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

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.