-1

Lets take a class A.

class A{
 
  public getAbsoluteLocation(){
    
   ....
  }
}

How can this class know in which directory it is located?

Gaurav Jeswani
  • 4,410
  • 6
  • 26
  • 47
DevSw
  • 11
  • 4

1 Answers1

1

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"));
  }

}
Somansh Reddy
  • 125
  • 2
  • 13