简体   繁体   English

抽象路径在java.io中意味着什么?

[英]What does abstract path means in java.io?

In java doc about 在java doc中

File#getPath()

writes: 写道:

 Converts this abstract pathname into a pathname string.

I try to write1 我试着写1

File file3 = new File("D:\\work");
System.out.println(file3.getPath());

In cmd I see D:\\\\work 在cmd中我看到D:\\\\work

I try to write2: 我试着写2:

File file4= new File("file4");
System.out.println(file4.getPath());

In cmd I see: 在cmd我看到:

file4

Thus I have a question: 因此我有一个问题:

What the difference between 有什么区别

abstract pathname 抽象路径名

and

pathname string 路径名字符串

?

An abstract pathname is a java.io.File object and a pathname string is a java.lang.String object. 抽象路径名java.io.File对象, 路径名字符串java.lang.String对象。 Both reference the same file on the disk. 两者都引用磁盘上的相同文件。

How do I know? 我怎么知道?

The first sentence of the Javadoc of java.io.File explains: java.io.File的Javadoc的第一句话解释了:

An abstract representation of file and directory pathnames. 文件和目录路径名的抽象表示。

It goes on to explain why: 它继续解释原因:

User interfaces and operating systems use system-dependent pathname strings to name files and directories. 用户界面和操作系统使用依赖于系统的路径名字符串来命名文件和目录。 This class presents an abstract, system-independent view of hierarchical pathnames. 此类提供了一个抽象的,与系统无关的分层路径名视图。

The abstract pathname is just the string form of the file/location held in the File object. 抽象路径名只是File对象中保存的文件/位置的字符串形式。

If you check the javadoc of File#toString() : 如果检查File#toString()的javadoc:

Returns the pathname string of this abstract pathname. 返回此抽象路径名的路径名字符串。 This is just the string returned by the getPath() method. 这只是getPath()方法返回的字符串。

See javadoc: abstract pathname = File 请参阅javadoc:abstract pathname = File

  1. An optional system-dependent prefix string, such as a disk-drive specifier, "/" for the UNIX root directory, or "\\\\" for a Microsoft Windows UNC pathname, and 可选的系统相关前缀字符串,例如磁盘驱动器说明符,UNIX根目录的“/”或Microsoft Windows UNC路径名的“\\\\”,以及
  2. A sequence of zero or more string names. 一个零个或多个字符串名称的序列。 [refering to directories and file [参考目录和文件

These are independent of operating system peculiarities of notation. 这些与操作系统的符号特性无关。

The string form gives you what you need to write on your current operating system to refer to that file. 字符串表单为您提供了在当前操作系统上编写以引用该文件所需的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM