Java Socket shutdownInput() 方法

2025 年 3 月 25 日 | 阅读 2 分钟

Java Socket 类的 shutdownInput() 方法会将指定套接字的输入流定位到流的末尾。当在套接字上调用此方法时,流的 available 方法将返回 0,并且其 read 方法将返回 -1(流结束)。

语法

参数

不适用

返回

不适用

抛出

IOException - 如果在关闭给定套接字时发生 I/O 错误

示例 1

输出

Output
The socket is connected: true
The socket is bounded: true
Input is shutdown: true

示例 2

输出

The socket is connected: true
The socket is bounded: true
Input is shutdown: true

示例 3

输出

Exception in thread "main" java.net.SocketException: Socket is not connected
	at java.net.Socket.shutdownInput(Socket.java:1523)
	at com.tpointtech.JavaSocketShutdownInputExample3.main(JavaSocketShutdownInputExample3.java:11)
下一主题Java Socket 类