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发行说明。
The Path class, introduced in the Java SE 7 release, is one of the primary entrypoints of the java.nio.file package. JavaSE7版本中引入的Path
类是java.nio.file
包的主要入口点之一。If your application uses file I/O, you will want to learn about the powerful features of this class.如果您的应用程序使用文件I/O,则需要了解此类的强大功能。
java.io.File
, you can still take advantage of the Path
class functionality by using the File.toPath method. java.io.File
的JDK7之前的代码,那么仍然可以通过使用File.toPath
方法来利用Path
类的功能。As its name implies, the 顾名思义,Path
class is a programmatic representation of a path in the file system. Path
类是文件系统中路径的编程表示。A Path
object contains the file name and directory list used to construct the path, and is used to examine, locate, and manipulate files.Path
对象包含用于构造路径的文件名和目录列表,并用于检查、定位和操作文件。
A Path
instance reflects the underlying platform. Path
实例反映了底层平台。In the Solaris OS, a 在Solaris操作系统中,路径使用Solaris语法(Path
uses the Solaris syntax (/home/joe/foo
) and in Microsoft Windows, a Path
uses the Windows syntax (C:\home\joe\foo
). /home/joe/foo
),而在Microsoft Windows中,路径使用Windows语法(C:\home\joe\foo
)。A Path
is not system independent. Path
不是独立于系统的。You cannot compare a 即使目录结构相同且两个实例都位于相同的相对文件中,也不能比较Solaris文件系统中的Path
from a Solaris file system and expect it to match a Path
from a Windows file system, even if the directory structure is identical and both instances locate the same relative file.Path
并期望它与Windows文件系统中的Path
匹配。
The file or directory corresponding to the 与Path
might not exist. Path
对应的文件或目录可能不存在。You can create a 您可以创建一个Path
instance and manipulate it in various ways: you can append to it, extract pieces of it, compare it to another path. Path
实例,并以各种方式对其进行操作:可以附加到它,提取它的片段,将它与另一个路径进行比较。At the appropriate time, you can use the methods in the 在适当的时候,可以使用Files
class to check the existence of the file corresponding to the Path
, create the file, open it, delete it, change its permissions, and so on.Files
类中的方法检查路径对应的文件是否存在、创建文件、打开文件、删除文件、更改其权限等。
The next page examines the 下一页将详细检查Path
class in detail.Path
类。