Java Socket getInputStream() methodThe 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 1Test it NowOutput: Input Stream: java.io.DataInputStream@1540e19d Example 2Test it NowOutput: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.getInputStream(Socket.java:903) at com.javaTpoint.JavaSocketGetInputStreamExample2.main(JavaSocketGetInputStreamExample2.java:24) Example 3Test it NowOutput: Exception in thread "main" java.net.SocketException: Socket is not connected at java.net.Socket.getInputStream(Socket.java:905) at com.javaTpoint.JavaSocketGetInputStreamExample3.main(JavaSocketGetInputStreamExample3.java:20) Next TopicJava Socket Class |
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