One of the major new features of Java 1.4 is a new Input/Output (I/O) architecture, intended for servers and other applications that require high-performance I/O. Features of this New I/O API include:
Network channels (the New I/O version of sockets) can be placed in nonblocking mode.
Multiple nonblocking channels can be multiplexed with a
Selector object. This means that
it is no longer necessary to create a new thread to monitor each
Files can be memory mapped.
Files, and sections of files, can be locked to prevent concurrent read and write access.
Charset class and related classes give better control over
character-to-byte encoding and byte-to-character decoding.
supports text matching with Perl 5-style regular expressions.
Although regular expressions are not directly related to I/O, they
were developed under the umbrella of the same Java Specification
Request (JSR) and are often considered to be part of the New I/O
This chapter demonstrates all of these features. To understand the
examples, an overview of the New I/O API is in order. Except for the
java.util.regex package already mentioned, the
bulk of the New I/O is in
and its subpackages.
Buffer class and various concrete subclasses, such as
for holding sequences of bytes, characters, and other primitive types. All actual I/O is done with byte buffers, but values of other primitive types can ...