In java doc about
File#getPath()
writes:
Converts this abstract pathname into a pathname string.
I try to write1
File file3 = new File("D:\\work");
System.out.println(file3.getPath());
In cmd I see D:\\work
I try to write2:
File file4= new File("file4");
System.out.println(file4.getPath());
In cmd I see:
file4
Thus I have a question:
What the difference between
abstract pathname
and
pathname string
?
An abstract pathname has two 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, and. A sequence of zero or more string names.
An abstract pathname consists of an optional prefix string, such as disk drive specifiers, “/” for Unix, or “\\” for Windows, and a sequence of zero or more string names. The prefix string is platform-dependent. The last name in the abstract pathname represents a file or directory.
A Path can represent a root, a root and a sequence of names, or simply one or more name elements. A Path is considered to be an empty path if it consists solely of one name element that is empty. Accessing a file using an empty path is equivalent to accessing the default directory of the file system.
An abstract pathname is a java.io.File
object and a pathname string is a java.lang.String
object. Both reference the same file on the disk.
How do I know?
The first sentence of the Javadoc of java.io.File
explains:
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.
If you check the javadoc of File#toString()
:
Returns the pathname string of this abstract pathname. This is just the string returned by the
getPath()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With