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 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.
See javadoc: abstract pathname = 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.