java获取classpath

时间:2022-05-22 14:51:41
public class PathTest {
public static void main(String[] args) {
//获取根路径三种方式
System.out.println(PathTest.class.getClassLoader().getResource(""));
System.out.println(ClassLoader.getSystemClassLoader().getResource(""));
System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
//获取当前类所在路径
System.out.println(PathTest.class.getResource(""));
}
}