The getCanonicalFile() method returns the canonical form of the file or directory. Equivalent to new File(file.getCanonicalPath()) method.
2. Method signature
Parameters:
method does not take any parameter
Returns
File - the canonical pathname of the specified file or directory
Throws
IOException - in case an I/O error occurs
SecurityException - when we do not have access to the file or directory
3. Examples
3.1. Program that compares getCanonicalFile() and getAbsoluteFile() methods
The output:
4. Conclusion
In this article, we presented File.getCanonicalFile() method that can be used to get the canonical representation of the file or directory. This method is behavior is similar to getCanonicalPath() with the difference in the result object.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}