File lightbulb moment
Apr. 7th, 2021 11:33 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
I was always puzzled by something in the
How could cleaning up a file path cause an
Today I passed a ridiculously long name to the "canonical" version and it said
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.