Lets take a class A.
class A{
public getAbsoluteLocation(){
....
}
}
How can this class know in which directory it is located?
Lets take a class A.
class A{
public getAbsoluteLocation(){
....
}
}
How can this class know in which directory it is located?
Assumption is that you just want to print the path. You can also return the value or perform any other operations based on your method return type.
class A {
public void getAbsoluteLocation() {
ClassLoader loader = A.class.getClassLoader();
System.out.println(A.class.getResource("A.class"));
}
}