Java Nio 简明教程
Java NIO - Overview
java.nio 包是在 java 1.4 中引入的。与 java I/O 相比,java NIO 中引入了面向缓冲区和通道的数据流进行 I/O 操作,这最终提供了更快的执行速度和更好的性能。
Java.nio package was introduced in java 1.4. In contrast of java I/O in java NIO the buffer and channel oriented data flow for I/O operations is introduced which in result provide faster execution and better performance.
NIO API 还提供了选择器,它引入了以异步或非阻塞方式侦听多个通道的 I/O 事件的功能。在 NIO 中,包括将缓冲区填充和清空到操作系统等最耗时的 I/O 活动在内的速度都得到了提升。
Also NIO API offer selectors which introduces the functionality of listen to multiple channels for IO events in asynchronous or non blocking way.In NIO the most time-consuming I/O activities including filling and draining of buffers to the operating system which increases in speed.
NIO API 的核心抽象如下:
The central abstractions of the NIO APIs are following −
-
Buffers,which are containers for data,charsets and their associated decoders and encoders,which translate between bytes and Unicode characters.
-
Channels of various types,which represent connections to entities capable of performing I/O operations
-
Selectors and selection keys, which together with selectable channels define a multiplexed, non-blocking I/O facility.