This section is being updated to reflect features and conventions of the upcoming release, JDK7. You can download the current JDK7 Snapshot from
java.net. We've published this preliminary version so you can get the most current information now, and so you can tell us about errors, omissions, or improvements we can make to this tutorial.
java.nio.filepackage and its related package,
java.nio.file.attribute, provide comprehensive support for file I/O and for accessing the file system. Though the API has many classes, you need to focus on only a few entrypoints — you will see that this API is very intuitive and easy to use.
The tutorial starts by asking what is a Path? Then the Path class, the primary entrypoint for the package, is introduced. Methods in the
Pathclass relating to syntactic operations are explained. The tutorial then moves on to
Pathmethods that deal with file operations. First, some concepts common to many file operations are introduced. The tutorial then covers methods for checking, deleting, copying, and moving files.
Next, some of the very powerful, but more advanced, topics are covered. First, the ability to recursively walk the file tree is demonstrated, followed by information on how to search for files using wild cards. Next, how to watch a directory for changes is explained and demonstrated. Then, methods that didn't fit elsewhere are given some attention.
Finally, if you have file I/O code written prior to JDK7, there is a map from the old API to the new API, as well as important information about the
File.toPathmethod for those who would like to leverage the new API without re-writing existing code.