The 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.
What is Java output stream?
The Java. io. OutputStream class is the superclass of all classes representing an output stream of bytes. An output stream accepts output bytes and sends them to some sink. Applications that need to define a subclass of OutputStream must always provide at least a method that writes one byte of output.
What does OutputStream write do?
write(byte[] b, int off, int len) method writes len bytes from the specified byte array starting at offset off to this output stream. Subclasses are encouraged to override this method and provide a more efficient implementation. … If b is null, a NullPointerException is thrown.