Absolute path is the full directory path .
Relative path is relative to the directory you are in, so if you are in the above directory, then if you reference file test.txt as relative, it assumes the same directory you are in. When you do ../ then it goes back one directory.
Suppose you are in a directory whose path is k... In this directory there is a file named a.txt
. Now
the absolute path is C:\A\B\a.txt
the relative path is a.txt
(as you are in the same directory).
Why you need a relative path
You need a relative path so that in your code you can use any file without depending on the path set by user. For example in your code you need to access a file. If you use absolute path then the path will change depending on the location where the user will set it.
But if you use relative path then the path will be always same as it will always be in your project folder. (or a fixed hiararchy)