Why should OutputStream be closed after inputstream in android

时光总嘲笑我的痴心妄想 提交于 2019-12-05 17:01:36

Looks like a bug in Android to me.

In Java whence this comes, closing the ObjectOutputStream at any time over an HttpURLConnection does nothing except flush the output (because the connection has to stay up to receive the response). Closing the input stream of an HttpURLConnection closes the entire connection, so a subsequent close of the ObjectOutputStream would do nothing.

I suspect Android does something bad to the connection when you do the ObjectOutputStream.close() first, such as closing it.

I would omit the ObjectOutputStream.close() altogether, you don't need it in either platform. The flush() is sufficient.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!