Home  >  Article  >  Java  >  What is NIO in Java

What is NIO in Java

(*-*)浩
(*-*)浩Original
2019-11-27 15:57:163363browse

What is NIO in Java

Java provides a second I/O system called NIO (New I/O). NIO provides I/O that is different from the standard I/O API. O processing method. It is Java's replacement for the traditional I/O API (since Java 1.4). ​ ​ ​ (Recommended learning: java course)

It supports buffer-oriented, channel-based I/O operation methods. With the introduction of JDK 7, the NIO system has been extended to provide enhanced support for file system functions and file handling. Due to these new features supported by the NIO file class, NIO is widely used in file processing.

NIO enables high-speed I/O for Java programmers without using custom native code. NIO moves the temporal I/O activity of filling, draining buffers, etc. back to the operating system, greatly speeding up operations.

The basic components of Java NIO are as follows:

What is NIO in Java

Channels and Buffers: in the standard I/O API , using character streams and byte streams. In NIO, channels and buffers are used. Data is always written to the channel from the buffer and read from the channel to the buffer.

Selectors: Java NIO provides the concept of "selectors". This is an object that can be used to monitor multiple channels, such as data arriving, connections opened, etc. Therefore, a single thread can monitor data from multiple channels.

Non-blocking I/O (Non-blocking I/O): Java NIO provides non-blocking I/O functionality. This application returns any available data immediately, the application should have a pooling mechanism to find out if more data is ready.

Let’s take a look at the application and operating system interfaces of non-blocking I/O:

What is NIO in Java

The above is the detailed content of What is NIO in Java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn