1、 Java NIO 概述
IO |
NIO |
面向流(Stream Oriented):单向的 |
面向缓冲区(Buffer Oriented):通道是单向的,也可以是双向的 |
阻塞IO(Blocking IO) |
非阻塞IO(Non Blocking IO) |
(无) |
选择器(Selectors) |
2、 Java NIO.2 之Path、Paths 与 Files 的使用
3、 自动资源管理
4、 缓冲区(Buffer)
方 法 |
描 述 |
Buffer flip() |
将limit设置为当前position,将position设置为 0,mark设置为-1 |
Buffer rewind() |
将position设为为 0, mark设为-1。可重复读 |
Buffer clear() |
将limit设为capacity,将position设为0,并将mark设为-1。数据没有清空 |
Buffer mark() |
对缓冲区设置mark |
Buffer reset() |
将位置 position 转到以前设置的 mark 所在的位置 |
boolean hasRemaining() |
判断缓冲区中是否还有元素 |
int remaining() |
返回 position 和 limit 之间的元素个数 |
Xxx[] array() |
返回XxxBuffer底层的Xxx数组 |
int capacity() |
返回 Buffer 的 capacity 大小 |
int limit() |
返回 Buffer 的界限(limit) 的位置 |
Buffer limit(int n) |
将设置缓冲区界限为 n, 并返回一个具有新 limit 的缓冲区对象 |
int position() |
返回缓冲区的当前位置 position |
Buffer position(int n) |
将设置缓冲区的当前位置为 n , 并返回修改后的 Buffer 对象 |
5、 通道(Channel)与文件通道(FileChannel)
6、管道(Pipe)中的SinkChannel和SourceChannel
7、 字符集(Charset)