关闭Input / OutputStream和直接关闭Socket有什么区别? [英] What is the difference between closing Input/OutputStream and closing Socket directly?

查看:84
本文介绍了关闭Input / OutputStream和直接关闭Socket有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道当我们在inputStream上调用close并使用与套接字关联的outStream时java会做什么。与套接字上的close调用有什么区别,即Socket.close()。

I just wondering what java does when we call close on the inputStream and outStream associated with a socket. What is the difference from the close call on the socket, i.e Socket.close().

如果我们只关闭套接字上的io流,但不关闭套接字,我们可以再次在套接字上重新打开io流吗?

if we just close the io stream on the socket, but not close the socket, can we reopen the io stream on the socket again?

提前致谢!

推荐答案

您应该关闭从套接字创建的最外面的输出流。这将冲洗它。关闭套接字或输入流不会这样做,所以它是不够的。关闭该输出流后,您无需执行任何其他操作。

You should close the outermost output stream you have created from the socket. That will flush it. Closing either the socket or the input stream doesn't do that so it isn't adequate. Having closed that output stream you don't need to do anything else.

这篇关于关闭Input / OutputStream和直接关闭Socket有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆