java.io中的抽象路径是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24611148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 13:27:57  来源:igfitidea点击:

What does abstract path means in java.io?

javafileiopath

提问by gstackoverflow

In java doc about

在java文档中

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

路径名串

?

?

采纳答案by Erwin Bolwidt

An abstract pathnameis a java.io.Fileobject and a pathname stringis a java.lang.Stringobject. Both reference the same file on the disk.

一个抽象路径名是一个java.io.File对象和路径名字符串是一个java.lang.String对象。两者都引用了磁盘上的同一个文件。

How do I know?

我怎么知道?

The first sentence of the Javadoc of java.io.Fileexplains:

Javadoc的第一句话java.io.File解释了:

An abstract representation of file and directory pathnames.

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

It goes on to explain why:

它继续解释原因:

User interfaces and operating systems use system-dependent pathname stringsto name files and directories. This class presents an abstract, system-independent view of hierarchical pathnames.

用户界面和操作系统使用依赖于系统的 路径名字符串来命名文件和目录。此类提供分层路径名的抽象的、独立于系统的视图。

回答by icza

The abstract pathname is just the string form of the file/location held in the Fileobject.

抽象路径名只是File对象中保存的文件/位置的字符串形式。

If you check the javadoc of File#toString():

如果您检查以下的 javadoc File#toString()

Returns the pathname string of this abstract pathname. This is just the string returned by the getPath()method.

返回此抽象路径名的路径名字符串。这只是getPath()方法返回的字符串。

回答by laune

See javadoc: abstract pathname = File

请参阅 javadoc:抽象路径名 = 文件

  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
  2. A sequence of zero or more string names. [refering to directories and file
  1. 可选的系统相关前缀字符串,例如磁盘驱动器说明符、UNIX 根目录的“/”或 Microsoft Windows UNC 路径名的“\\”,以及
  2. 零个或多个字符串名称的序列。[指目录和文件

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.

字符串形式为您提供了需要在当前操作系统上写入以引用该文件的内容。