Java – how do I force an OutputStream object to refresh without closing it?

My problem lies in the following assumptions. I hope these assumptions are correct, because I believe these are what I read when I searched my questions on Google:

>Closing the socket's OutputStream also closes the socket > the flush () method of OutputStream does nothing

So I basically need to refresh the data from my OutputStream object to make my application work properly

If you are interested in more information, please refer to the following two links:

. Weird behavior : sending image from Android phone to Java server (code working)

This problem is solved by closing OutputStream Doing so will flush all data to the other end of the socket and make my application work further, but this fix quickly caused problem 2 - the corresponding socket is also closed:

. SocketException – ‘Socket is closed’ even when isConnected() returns true

Solution

You can call the flush method of OutputStream instead of close Concrete classes inherited from OutputStream will override flush () to perform operations other than any operation (writing data to a file or sending it over the network)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>