I am learning Java and this is what I realized regarding different paths:
Relative -incomplete path that exists relative to some directory, for example: \ data \ file.txt Absolute -full path starting from drive: C: \ users \ data \ file.txt
What is the canonical path and why is it needed? I tried to understand the English-language sources (I don't know English well), but I only realized that the canonical path lacks dynamic links (what is this?) And things like: ... \ (again, what is this?).
Please explain in simple terms what it is.
-
Answer # 1
Honestly, this is the first time I came across this name. But the first link explains this: In different operating environments (not in Windows), it is possible to make the path to a specific file such that it will not work in Windows. For example, on an ext4 filesystem, you can reference it like this:
\ var \ some \ there \ here \ where \ not \ be \ .. \ .. \ point \ file.txt
It sometimes makes sense when you create a path using a script that runs from some folder inside the system and stupidly substitutes ".. \ .. \ point \ file.txt" to the path to the current subdirectory. But in this case, the path:
\ var \ some \ there \ where \ point \ file.txt
will lead to the same file. Just like the path:
.. \ .. \ point \ file.txt will also lead to this file if you are in
you are currently in the folder:
\ var \ some \ there \ here \ where \ not \ be \
And so. The "canonical path" is the path that will be as simple and strict as possible. "canon". That is, without all these strange constructions. There is also a good example from the link:
absolute path: C: \ abc \ .. \ abc \ file.txt
canonical path: C: \ abc \ file.txt
Both of these paths are correct. But the second is canonical. Roughly speaking, Windows users always use only the canonical path.
It seems that everything is correct, but what does Windows have to do with it? In Windows, two points work in the same way.
Pavel Mayorov2021-02-23 20:47:04As far as I remember, the following construction will not work in Windows: C: \ This \ Very \ Strange \ Path \ .. \ .. \ .. \ Good \ Path \
Roman Bush2021-02-23 20:47:04By the way, the "canonical" path for this path will be: C: \ This \ Good \ Path \
Roman Bush2021-02-23 20:47:04However, I could be wrong. I have been under Linux for a long time. And I hardly remember how it works in Windows. I only keep it for toys.
Roman Bush2021-02-23 20:47:04You remember it very strangely. Would have taken and checked before writing nonsense, since you still have Windows.
Pavel Mayorov2021-02-23 20:47:04
The first link is in English. Unfortunately, I hardly know English, and I found detailed explanations only on English-language sites (alas, the translator does not allow me to fully understand the meaning of the canonical path)
Zhenyria2021-02-23 20:47:04