jbanana: Badly drawn banana (Default)
[personal profile] jbanana
I was always puzzled by something in the File class. It has getAbsolutePath() and getCanonicalPath() and they both do almost the same thing: return a fully qualified name of the file. One difference is that the "absolute" version doesn't simplify paths with ".." which makes the "canonical" version always looks tempting. But that version throws IOException, so you need a try block, which makes it a pain.

How could cleaning up a file path cause an IOException? Documentation says "construction of the canonical pathname may require filesystem queries" and I've never known what that could mean.

Today I passed a ridiculously long name to the "canonical" version and it said IOException: The parameter is incorrect. Shortening the name made it work. I think it's telling me "that file cannot possibly exist on this file system", which kind-of fits into the "filesystem queries" category mentioned in the docs.

May 2025

M T W T F S S
   1234
5678 91011
12131415161718
19202122232425
262728293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 7th, 2025 07:46 am
Powered by Dreamwidth Studios