This examples shows how to get a path name or location from where our class is loaded.
package org.kodejava.example.lang;
public class CodeSourceLocation {
public static void main(String[] args) {
CodeSourceLocation csl = new CodeSourceLocation();
csl.getCodeSourceLocation();
}
private void getCodeSourceLocation() {
// The the location from where the class is loaded.
System.out.println("Code source location: " +
getClass().getProtectionDomain().getCodeSource().getLocation());
}
}
Latest posts by Wayan (see all)
- How do I create a generic class in Java? - January 1, 2021
- How do I convert java.util.TimeZone to java.time.ZoneId? - April 25, 2020
- How do I get a list of all TimeZones Ids using Java 8? - April 25, 2020