龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

java NIO 详解(2)

时间:2014-10-30 02:05来源:网络整理 作者:网络 点击:
分享到:
从管道读取数据 从读取管道的数据,需要访问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值会告诉我们多少字节被读进了缓冲区。

精彩图集

赞助商链接