The result you get is absolutely right.
I think you misunderstood the use of class.getResource .
Suppose you have the package com.test and MyClass inside this package.
This MyClass.class.getResource(".") give you the location of the file you are executing from. Locates the MyClass .
This MyClass.class.getResource("..") move up 1 level in your package structure. Thus, this will return the location of the test directory.
This MyClass.class.getResource("../..") will go further 1 level up. Thus, this will return the location of the com directory.
Now this MyClass.class.getResource("../../..") will try to move up 1 level further, but since there is no package directory, this will return null .
So, class.getResource will not exit a specific package structure and begin accessing your computer directory. Here's how it doesn't work. This is done only in the structure of the current class .
source share