The getCanonicalPath() method returns the canonical path of the given file or directory. The precise definition of this method is system-dependent. The method first uses the absolute form of the path and then removes all redundant names such as . and .. from the pathname. It is better to explain a real-life example of how this method works with comparison to getAbsolutePath().
2. Method signature
method does not take any parameter
String - the canonical pathname string of the specified file or directory
IOException - if an I/O error occurs
SecurityException - if a required system property value cannot be accessed
3.1. Program that compares getCanonicalPath() and getAbsolutePath() methods
In this article, we presented getCanonicalPath() method that can be used to get the unique form of the file or directory. Note that this method works differently on UNIX and Windows OS.