Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why getCanonicalPath throws checked exception while getAbsolutePath does not?

Tags:

java

io

I know the differences between the two by reading some related text. But I am curious that why getCanonicalPath() throws checked exception while getAbsolutePath() does not throw any?

like image 344
ipkiss Avatar asked Sep 11 '11 14:09

ipkiss


People also ask

What is the difference between canonical path and absolute path?

A canonical path is always an absolute path. Converting from a path to a canonical path makes it absolute (usually tack on the current working directory so e.g. ./file. txt becomes c:/temp/file. txt ).

What is file getCanonicalPath()?

The getCanonicalPath() method is a part of Path class. This function returns the Canonical pathname of the given file object. If the pathname of the file object is Canonical then it simply returns the path of the current file object. The Canonical path is always absolute and unique, the function removes the '.


1 Answers

But I am curious that why getCanonicalPath() throws checked exception while getAbsolutePath() does not throw any?

It says why in the documentation for getCanonicalPath:

IOException - If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries

like image 170
aioobe Avatar answered Oct 04 '22 20:10

aioobe