A simple look at the description, the example is the most important.
1, GetPath ():
Returns the path to the definition, (that is, what path you write, and what path he returns)
2, GetAbsolutePath ():
Returns an absolute path, but does not process "." and ".." The situation
3, Getcanonicalpath ():
Returns the normalized absolute path, which is equivalent to the "." In GetAbsolutePath (). and ".." Parse the correct path to the corresponding
First example: (using: ". \\src\\test.txt" a point path)
File File = new file (". \\src\\test.txt"); System.out.println (File.getpath ()); System.out.println (File.getabsolutepath ()); System.out.println (File.getcanonicalpath ()); Results:. \src\test.txtd:\workspace\java_io\.\src\test.txtd:\workspace\java_io\src\test.txt
The second example: (using: ". \\src\\test.txt "Two-point path)
File File = new file (".. \\src\\test.txt "); System.out.println (File.getpath ()); System.out.println (File.getabsolutepath ()); System.out.println (File.getcanonicalpath ()); Results: \src\test.txtd:\workspace\java_io\. \src\test.txtd:\workspace\src\test.txt Note that the path to the result is not the same as a point, because he resolves the "." and ".." The situation.
A third example: (using: "D:\\test\\absolutetest.txt" absolute path)
File File = new file ("D:\\test\\absolutetest.txt"); System.out.println (File.getpath ()); System.out.println (File.getabsolutepath ()); System.out.println (File.getcanonicalpath ()); Results: d:\test\absolutetest.txtd:\test\absolutetest.txtd:\test\ AbsoluteTest.txt
Conclusion:
1. When the input is an absolute path, the absolute path is returned.
2. When the input is a relative path:
2.1, GetPath () return is the path in the file construction method, what is what, does not increase not minus
2.2, GetAbsolutePath () returned is actually the content of User.dir+getpath (), from the above view: D:\workspace\java_io\.\src\test.txt,d:\workspace\java_io \.. \src\test.txt, can be drawn.
2.3. Getcanonicalpath () returns the standard path to fully parse the symbol
What is the difference between the file class GetPath (), GetAbsolutePath (), Getcanonicalpath () in Java?