The result you are getting is perfectly right.
I think you have misunderstood the use of class.getResource
.
Lets say you have package com.test
and MyClass
inside this package.
This MyClass.class.getResource(".")
will give you the location of the file you are executing from. Means location of MyClass
.
This MyClass.class.getResource("..")
will go 1 level up in your package structure. So, this will return the location of directory test
.
This MyClass.class.getResource("../..")
will go further 1 level up. So, this will return the location of directory com
.
Now, this MyClass.class.getResource("../../..")
will attempt to go further 1 level up but since there is no package directory exists, this will return null.
So, class.getResource
will not go out of the defined package structure and start accessing your computer directory. This is how this does not work. This only searches within your current class package structure.