我看先看一下通过socket取得的流的运行类型
InputStream inputStream = socket.getInputStream();
可以看到是SocketInputStream
看一下SocketInputStream的close方法
private boolean closing = false;
public void close() throws IOException {
// Prevent recursion. See BugId 4484411
if (closing)
return;
closing = true;
if (socket != null) {
if (!socket.isClosed())
socket.close();
} else
impl.close();
closing = false;
}
关闭input流的时候, 首先会把closing状态 置为true
然后检查socket是否关闭, 如果socket没关闭 会把socket也关闭掉
Original: https://www.cnblogs.com/recorderM/p/15991943.html
Author: 紫英626
Title: 与socket相关的流
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/572848/
转载文章受原作者版权保护。转载请注明原作者出处!