java NIO 详解(2)
从管道读取数据 从读取管道的数据,需要访问source通道,像这样: [code] Pipe.SourceChannel sourceChannel = pipe.source(); 调用source通道的read()方法来读取数据,像这
从管道读取数据
从读取管道的数据,需要访问source通道,像这样:
[code]
Pipe.SourceChannel sourceChannel = pipe.source();
调用source通道的read()方法来读取数据,像这样:
复制代码 代码如下:
ByteBuffer buf = ByteBuffer.allocate(48);
int bytesRead = inChannel.read(buf);
read()方法返回的int值会告诉我们多少字节被读进了缓冲区。
精彩图集
精彩文章