javaAPI文档翻译之Java.io.File

Java.lang.Object

Java.io.File


Public classFile

Extend Object

ImplementsSerializable,Comparable<File>


An abstractrepresentation of file and directory pathnames.

文件和目录路径名的抽象表示

Userinterfaces and operating systems use system-dependent pathnamestrings to name files and directories. This classpresents an abstract, system-independent view of hierarchical pathnames.An abstract pathnamehas two components:

用户界面和操作系统使用系统相关的路径名来命名文件和目录的字符串。此类提供了一个抽象,独立系统的分层路径名的视图。抽象路径名有两个组件:

Hastwo components:

An optional system-dependent prefix string,such as a disk-drive specifier, "/" for the UNIX root directory,or "\\\\" for a Microsoft Windows UNC pathname.

一个可选的系统相关的前缀字符串,如磁盘驱动器说明符,"/"对于UNIX根目录,或者"为microsoftwindowsUNC路径名

Asequence of zero or more String names.

零个或多个字符串名称序列。

Thefirst name in an abstract pathname may be a directory name or, in the case ofMicrosoft Windows UNC pathnames, a hostname. Each subsequent name in anabstract pathname denotes a directory; the last name may denote either adirectory or a file. The empty abstract pathname has no prefix and an emptyname sequence.

抽象路径名中的第一个名称可以是一个目录名,如果在Microsoft WindowsUNC路径名的情况下,则为主机名。在抽象路径名的每个后续的名字代表一个目录;最后可能表明一个目录或文件名称。空的抽象路径名没有前缀和一个空序列名称。

Theconversion of a pathname string to or from an abstract pathname is inherentlysystem-dependent. When an abstract pathname is converted into a pathnamestring, each name is separated from the next by a single copy of thedefault separator character. The default name-separator character is definedby the system property file.separator, and is made available in the public static fields separator and separatorChar of this class. When a pathname string isconverted into an abstract pathname, the names within it may be separated bythe default name-separator character or by any other name-separator characterthat is supported by the underlying system.

路径名字符串转换成抽象路径名或者从抽象路径名转换成路径名字符串是固有的,具有系统依赖性的。当一个抽象的路径名转换成路径名字符串时,每一个名字被默认的分隔符的单一副本分割。默认的分隔符字符名称是由系统属性file.separator,以及提供此类的公共静态属性separatorseparatorChar所定义.当一个路径名字符串被转换成一个抽象路径名时,通过默认的名称-分隔符特性或者通过其他由基础系统支持的名称-分隔符特性分割。

Apathname, whether abstract or in string form, may be either absolute or relative. An absolute pathnameis complete in that no other information is required in order to locate thefile that it denotes. A relative pathname, in contrast, must be interpreted interms of information taken from some other pathname. By default the classes inthe java.io packagealways resolve relative pathnames against the current user directory. Thisdirectory is named by the system property user.dir, and is typically the directory in which the Javavirtual machine was invoked.

路径名,无论是抽象的或以字符串的形式,可以是绝对路径或相对路径。绝对路径名是完整的,不需要其他信息才能找到它表示的文件。相对路径名,相反,必须采取一些其他路径名信息方面的解释。默认情况下,java.io包中的类总是能解决当前用户目录的相对路径名。这个目录由系统属性user.dir命名,并且通常是调用java虚拟机的目录。

The parent of an abstractpathname may be obtained by invoking the getParent() method of this class and consists of thepathname's prefix and each name in the pathname's name sequence except for thelast. Each directory's absolute pathname is an ancestor of any File object with an absolute abstract pathnamewhich begins with the directory's absolute pathname. For example, the directorydenoted by the abstract pathname"/usr" is an ancestor of the directory denoted by the pathname "/usr/local/bin".

抽象路径名的父级可以通过调用该类的 getParent()方法获得,该父级包含了路径名的前缀以及除了路径名最后名称序列以外的名称序列的每一个名字。每个目录的绝对路径名是与目录的绝对路径开头的绝对抽象路径名的任何文件对象的祖先。例如,目录所表示的抽象路径名"/usr/"所指的目录路径名的祖先是"/usr/local/bin"。

The prefix conceptis used to handle root directories on UNIX platforms, and drive specifiers,root directories and UNC pathnames on Microsoft Windows platforms, as follows:

前缀概念用于处理UNIX平台上的根目录和驱动器说明符,微软Windows平台上的根目录和UNC路径名,如下所示:

  • For UNIX platforms, the prefix of an absolute pathname is always "/". Relative pathnames have no prefix. The abstract pathname denoting the root directory has the prefix "/" and an empty name sequence.
  • 对于UNIX平台,总是绝对路径名的前缀是"/"。相对路径名,没有前缀。 抽象指根目录路径名拥有前缀"/"和一个空序列名称。
  • For Microsoft Windows platforms, the prefix of a pathname that contains a drive specifier consists of the drive letter followed by "" and possibly followed by "\\" if the pathname is absolute. The prefix of a UNC pathname is "\\\\"; the hostname and the share name are the first two names in the name sequence. A relative pathname that does not specify a drive has no prefix.
  • 微软Windows平台上,路径名的前缀包含后跟":"驱动器字母的驱动器说明符并且可能带"\\",如果是绝对路径名。UNC路径名的前缀是"\\\";主机名和共享名称是序列名称中的前两名。相对路径名,它不指定没有前缀的驱动器。

Instancesof this class may or may not denote an actual file-system object such as a fileor a directory. If it does denote such an object then that object resides ina partition.A partition is an operating system-specific portion of storage for a filesystem. A single storage device (e.g. a physical disk-drive, flash memory,CD-ROM) may contain multiple partitions. The object, if any, will reside on thepartition named by someancestor of the absolute form of this pathname.

此类的实例可以也可以不表示一个实际文件系统对象,如文件或目录。如果它是指这样一个对象,然后该对象驻留在一个分区。分区是一个特定于操作系统的文件系统的存储的部分。单个存储设备(例如:一个物理磁盘驱动器、闪存、cd-rom)可以包含多个分区。对象,如果有的话,将驻留在由一些这个路径名的绝对形式的祖先命名分区。

A filesystem may implement restrictions to certain operations on the actualfile-system object, such as reading, writing, and executing. These restrictionsare collectively known as access permissions. The file system may have multiple sets of accesspermissions on a single object. For example, one set may apply to theobject's owner,and another may apply to all other users. The access permissions on an objectmay cause some methods in this class to fail.

文件系统可以实现在实际文件系统对象对某些操作的限制,如读、写和执行。这些统称为访问权限(accesspermissions)的限制。文件系统对一个单一对象可以有多重访问权限设置。例如:一套可以适用于对象的所有者,而另一个可以适用于其他所有用户。对某个对象的访问权限可能会导致此类中的某些方法失败。

Instancesof the File class areimmutable; that is, once created, the abstract pathname represented by aFile object will never change.

File类的实例是不可变的;也就是说,一旦创建,由一个File对象表示的抽象路径名不会改变。

Interoperabilitywith java.nio.file package ( java.no.file包的互操作性)The java.nio.file package defines interfaces andclasses for the Java virtual machine to access files, file attributes, and filesystems. This API may be used to overcome many of the limitations of the java.io.Fileclass. The toPath method may be used to obtain a Path that uses the abstract path represented bya Fileobjecttolocate a file. The resulting Path may be used withthe Files class to provide more efficient andextensive access to additional file operations, file attributes, and I/Oexceptions to help diagnose errors when an operation on a file fails.

java.nio.file包为Java虚拟机访问文件定义了接口和类,文件属性和文件系统。这个API可以被用来克服java.io.Fileclass的许多局限性。该 toPath( ) 方法可用于获取一个使用文件对象所表示的抽象路径的路径来查找文件。可以使用生成的路径与文件类,以提供更有效和广泛的访问其他文件操作,文件属性和 I/O exceptions以帮助诊断文件上的操作失败时出现错误。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值