Java Socket getInputStream() method25 Mar 2025 | 2 min read The getInputStream() method of Java Socket class returns an input stream for the given socket. If you close the returned InputStream, then it will close the linked socket. SyntaxParameterNA ReturnThe getInputStream() returns an input stream for reading bytes from this socket. ThrowsIOException- if an Input/Output error occurs while creating the input stream or if this socket is closed or the given socket is not connected, or the socket input has been shut down using shutdownInput() Example 1Output: Input Stream: java.io.DataInputStream@1540e19d Example 2Output: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.getInputStream(Socket.java:903) at com.tpointtech.JavaSocketGetInputStreamExample2.main(JavaSocketGetInputStreamExample2.java:24) Example 3Output: Exception in thread "main" java.net.SocketException: Socket is not connected at java.net.Socket.getInputStream(Socket.java:905) at com.tpointtech.JavaSocketGetInputStreamExample3.main(JavaSocketGetInputStreamExample3.java:20) Next TopicJava Socket Class |
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India