The main differences between IO and NIO in Java are as shown in the figure:
1. Stream-oriented and buffer-oriented
IO is stream-oriented, and NIO is buffer-oriented.
Java IO is stream-oriented meaning that one or more bytes are read from the stream at a time until all bytes are read, and they are not cached anywhere.
Java NIO's buffer-oriented approach is slightly different. The data is read into a buffer that it processes later, moving back and forth in the buffer as needed.
2. Blocking and non-blocking IO
The various streams of Java IO are blocking. When a thread calls read() or write(), the thread is blocked until some data is read, or the data is completely written.
The non-blocking mode of Java NIO allows a thread to send a request to read data from a certain channel, but it can only get the currently available data. If no data is currently available, nothing will be obtained. Instead of keeping the thread blocked, the thread can continue to do other things until the data becomes readable.
3. Selector
Java NIO's selector allows a single thread to monitor multiple input channels. You can register multiple channels using one selector. A separate thread is then used to "select" channels that already have input that can be processed, or select channels that are ready to be written to. This selection mechanism makes it easy for a single thread to manage multiple channels.
Recommended tutorial: java tutorial
The above is the detailed content of The difference between java nio and io. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

Atom editor mac version download
The most popular open source editor