简体   繁体   中英

Which to use? new InputStreamReader with Socket.getInputStream or System.in

Do anyone know what is the difference between these two lines of codes?

BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String inputLine = in.readLine();

BufferedReader d = new BufferedReader(new InputStreamReader(System.in));
String inputLine = d.readLine();

They seem to serve the same purpose which is to receive user keyboard input.

System.in reads data from the "standard" input stream:

This stream is already open and ready to supply input data. Typically this stream corresponds to keyboard input or another input source specified by the host environment or user.

clientSocket.getInputStream reads data from the specific "client socket" you created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM