-
- All Superinterfaces:
-
AutoCloseable,Closeable
- All Known Subinterfaces:
-
AsynchronousByteChannel,AsynchronousChannel,ByteChannel,GatheringByteChannel,InterruptibleChannel,MulticastChannel,NetworkChannel,ReadableByteChannel,ScatteringByteChannel,SeekableByteChannel,WritableByteChannel
- 所有已知实现类:
-
AbstractInterruptibleChannel,AbstractSelectableChannel,AsynchronousFileChannel,AsynchronousServerSocketChannel,AsynchronousSocketChannel,DatagramChannel,FileChannel,Pipe.SinkChannel,Pipe.SourceChannel,SctpChannel,SctpMultiChannel,SctpServerChannel,SelectableChannel,ServerSocketChannel,SocketChannel
public interface Channel extends Closeable
I / O操作的关系。通道表示与实体的开放连接,例如硬件设备,文件,网络套接字或能够执行一个或多个不同I / O操作(例如读取或写入)的程序组件。
渠道是开放的还是封闭的。 通道在创建时打开,一旦关闭,它将保持关闭状态。 一旦某个通道关闭,任何在其上调用I / O操作的尝试都将导致抛出
ClosedChannelException。 可以通过调用其isOpen方法来测试通道是否打开。通常,通道旨在对多线程访问安全,如扩展和实现此接口的接口和类的规范中所述。
- 从以下版本开始:
- 1.4
-
-
方法详细信息
-
isOpen
boolean isOpen()
判断此频道是否已打开。- 结果
-
true当且仅当此频道已打开时
-
close
void close() throws IOException关闭此频道。关闭通道后,进一步尝试调用I / O操作将导致抛出
ClosedChannelException。如果此通道已关闭,则调用此方法无效。
可以随时调用此方法。 但是,如果某个其他线程已经调用了它,那么另一个调用将阻塞,直到第一次调用完成,之后它将返回而不起作用。
- Specified by:
-
close,接口AutoCloseable - Specified by:
-
close在界面Closeable - 异常
-
IOException- If an I/O error occurs
-
-