Java Socket getOutputStream() methodThe getOutputStream() method of Java Socket class returns an output stream for the given socket. If you close the returned OutputStream then it will close the linked socket. SyntaxParameterNA ReturnThe getOutputStream() returns an output stream for writing bytes to this socket. ThrowsIOException- if an I/O error occurs when creating the output stream or if the socket is not connected. Example 1Test it NowOutput: Output Stream: java.io.DataOutputStream@1540e19d Example 2Test it NowOutput: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.getOutputStream(Socket.java:943) at com.javaTpoint.JavaSocketGetOutputStreamExample2.main(JavaSocketGetOutputStreamExample2.java:22) Example 3Test it NowOutput: Exception in thread "main" java.net.SocketException: Socket is not connected at java.net.Socket.getOutputStream(Socket.java:945) at com.javaTpoint.JavaSocketGetOutputStreamExample3.main(JavaSocketGetOutputStreamExample3.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