Java如何从加载类的地方获取路径?
本示例说明如何从加载类的位置获取路径名或位置。
package org.nhooo.example.lang;
public class CodeSourceLocation {
public static void main(String[] args) {
CodeSourceLocation csl = new CodeSourceLocation();
csl.getCodeSourceLocation();
}
private void getCodeSourceLocation() {
//加载类的位置。
System.out.println("Code source location: " +
getClass().getProtectionDomain().getCodeSource().getLocation());
}
}