The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
Note: This tutorial reflects the file I/O mechanism introduced in the JDK 7 release. 注意:本教程反映了JDK 7版本中引入的文件I/O机制。The Java SE 6 version of the File I/O tutorial was brief, but you can download the Java SE Tutorial 2008-03-14 version of the tutorial which contains the earlier File I/O content.文件I/O教程的JavaSE6版本很简短,但您可以下载包含早期文件I/O内容的Java SE教程2008-03-14版本。
The java.nio.file
package and its related package, java.nio.file.attribute
, provide comprehensive support for file I/O and for accessing the default file system. java.nio.file
包及其相关包java.nio.file.attribute
为文件I/O和访问默认文件系统提供了全面的支持。Though the API has many classes, you need to focus on only a few entry points. 尽管API有很多类,但您只需要关注几个入口点。You will see that this API is very intuitive and easy to use.您将看到此API非常直观且易于使用。
The tutorial starts by asking what is a path? 本教程首先询问什么是路径?Then, the Path class, the primary entry point for the package, is introduced. 然后,介绍包的主要入口点Path类。Methods in the 解释了Path
class relating to syntactic operations are explained. Path
类中与语法操作相关的方法。The tutorial then moves on to the other primary class in the package, the 然后,本教程将转到包中的另一个主要类Files
class, which contains methods that deal with file operations. Files
类,该类包含处理文件操作的方法。First, some concepts common to many file operations are introduced. 首先,介绍了许多文件操作所共有的一些概念。The tutorial then covers methods for checking, deleting, copying, and moving files.然后,本教程介绍检查、删除、复制和移动文件的方法。
The tutorial shows how metadata is managed, before moving on to file I/O and directory I/O. 本教程将在继续讨论文件I/O和目录I/O之前展示元数据的管理方式。Random access files are explained and issues specific to symbolic and hard links are examined.解释了随机访问文件,并研究了符号链接和硬链接的特定问题。
Next, some of the very powerful, but more advanced, topics are covered. 接下来,将介绍一些非常强大但更高级的主题。First, the capability to recursively walk the file tree is demonstrated, followed by information about 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 the Java SE 7 release, there is a map from the old API to the new API, as well as important information about the 最后,如果您在Java SE 7发行版之前编写了文件I/O代码,那么就有一个从旧API到新API的映射,以及有关File.toPath
method for developers who would like to leverage the new API without rewriting existing code.File.toPath
方法的重要信息,供希望在不重写现有代码的情况下利用新API的开发人员使用。