在java文档中关于
File#getPath()
写道:
Converts this abstract pathname into a pathname string.
我试着写1
File file3 = new File("D:\\work");
System.out.println(file3.getPath());
在 cmd 中我看到 D:\\work
我试着写2:
File file4= new File("file4");
System.out.println(file4.getPath());
在 cmd 中我看到:
file4
因此我有一个问题:
有什么区别
abstract pathname
和
pathname string
?
最佳答案
一个抽象路径名是一个java.io.File
对象,一个路径名字符串是一个java.lang.String
对象。两者都引用磁盘上的同一个文件。
我怎么知道?
java.io.File
的Javadoc第一句解释:
An abstract representation of file and directory pathnames.
它继续解释原因:
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.
关于java - 抽象路径在 java.io 中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24611148/