support is required for full functionality of this page.
NIO and NIO.2 Examples
The examples in the following table show how to use the NIO APIs.
Grep.java Searches a list of files for lines that match a
given regular-expression pattern. Demonstrates NIO mapped byte
buffers, charsets, and regular expressions.
Sum.java Computes 16-bit checksums for a list of files.
Uses NIO mapped byte buffers for speed.
TimeQuery.java Asks a list of hosts what time it is. Is a simple,
blocking program that demonstrates NIO socket channels (connection
and reading), buffer handling, charsets, and regular
TimeServer.java Listens for connections and tells callers what
time it is. Is a simple, blocking program that demonstrates NIO
socket channels (accepting and writing), buffer handling, charsets,
and regular expressions.
Ping.java Connects to each of a list of hosts and measures
the time required to complete the connection. Uses a selector and
two additional threads to demonstrate non-blocking connects and the
multithreaded use of a selector.
NBTimeServer.java Implements a non-blocking Internet time
The NIO.2 examples in the following table can be accessed in
your JDK 7 installation under
Changes the permissions of files in a manner
similar to the chmod(1) utility.
Copies files in a manner similar to the cp(1)
Prints out disk space information similar to the
Prints out a file's type.
Watches a directory (or tree) for changes to
Lists, gets, and deletes the user-defined
attributes of a file.
Parses and represents a multicast address.
Reads a message from a multicast datagram.
Sends a message in a multicast datagram to a given
This directory contains a simple NIO-based
HTTP/HTTPS server example. See the README.txt file for further