Java NIO Tutorial

Posted winner-0715

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java NIO Tutorial相关的知识,希望对你有一定的参考价值。

Java NIO (New IO) is an alternative IO API for Java (from Java 1.4), meaning alternative to the standardJava IO and Java Networking API‘s. Java NIO offers a different way of working with IO than the standard IO API‘s.

Java NIO: Channels and Buffers

In the standard IO API you work with byte streams and character streams. In NIO you work with channels and buffers. Data is always read from a channel into a buffer, or written from a buffer to a channel.

Java NIO: Non-blocking IO

Java NIO enables you to do non-blocking IO. For instance, a thread can ask a channel to read data into a buffer. While the channel reads data into the buffer, the thread can do something else. Once data is read into the buffer, the thread can then continue processing it. The same is true for writing data to channels.

Java NIO: Selectors

Java NIO contains the concept of "selectors". A selector is an object that can monitor multiple channels for events (like: connection opened, data arrived etc.). Thus, a single thread can monitor multiple channels for data.

How all this works is explained in more detail in the next text in this series - the Java NIO overview.

以上是关于Java NIO Tutorial的主要内容,如果未能解决你的问题,请参考以下文章

Java:NIO 和 NIO.2 到底有啥区别?

Java NIO:NIO概述

Java NIO系列教程 Java NIO与IO

Java NIO2:NIO概述

Java NIO系列教程 Java NIO与IO

Java Nio 十Java NIO Files