This examples shows how to get a path name or location from where our class is loaded.
package org.kodejava.lang;
public class CodeSourceLocation {
public static void main(String[] args) {
CodeSourceLocation csl = new CodeSourceLocation();
csl.getCodeSourceLocation();
}
private void getCodeSourceLocation() {
// The location from where the class is loaded.
System.out.println("Code source location: " +
getClass().getProtectionDomain().getCodeSource().getLocation());
}
}
The code snippet print the following output:
Code source location: file:/F:/Wayan/Kodejava/kodejava-example/kodejava-lang/target/classes/
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024