In jdk1.4, a new package was added, java.nio.*, which introduced the new JAVAI/O library to speed up, and in fact, the old I/O package was re-implemented using NIO.
What does this n in relation to Io,nio mean? "Java programming thought" called the small title "New I/O", the other is the first letter of Non-blocking, anyway, NiO is indeed a new processing non-blocking IO.
Several core components of NIO: Chennels (channel), buffers (cache), selectors (selector).
We can think of the channel as a large tank filled with water, while the cache (buffer) is a bucket, the bucket can be filled with water to be transported to another place, we do not have direct contact with the tank, are directly through the bucket (Buffer) interaction. In order to transport more water faster, we can use multiple buckets, and we can choose (Selector) which buckets how to fill the water, of course, we can not only from the tank through the bucket water can also be sent to the water tank.
The main channel implementations in Java are:
FileChannel: For file io, you can get the file channel through the Fileinputstream,fileoutputstream,randomaccessfile object's Getchannel ().
Datagramchannel: is a channel that can send and receive UDP packets. Use Datagramchannel.open () to open the channel.
Socketchannel: is a channel that is connected to a TCP network socket. Get using Socketchannel.open ().
Serversocketchannel: is a selectable channel for stream-oriented listening sockets, obtained using Serversocketchannel.open ().
The NIO Foundation in Java