Java new IO

Traditional IO

Stream oriented input / output systems such as InputStream, OutputStream, reader and writer in Java are regarded as traditional io. Traditional IO is blocking input and output, and is processed by byte movement, that is, traditional IO can only process one byte at a time, which is not efficient.

New IO

The new IO has the same purpose as the traditional IO, and is used for input and output functions. However, the new IO uses the memory mapping file to process input and output. The new IO maps the file or a section of the file into memory, so that the file can be accessed like memory. This method is much faster than the traditional io.

New IO related packages in Java are as follows:

An enumeration class is created in the test class to record the character set encoding. The string used for testing is a string written directly, which is the same as the encoding format of the native workspace.

Using selector

Selector is mainly used for non blocking socket communication. It is used with selectablechannel.

Selectablechannel represents a channel object that can support non blocking IO operations. It can be registered to the specified selector using the register () method. This registration relationship is represented by the selectionkey instance. The selector object provides a select () method that allows applications to monitor multiple IO channels simultaneously.

The selectablechannel object supports blocking and non blocking modes (all channels are in blocking mode by default). Sellablechannel provides the following two methods to set and return the mode status of the channel:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>