java获取classpath

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(""));
    }
}
原文地址:https://www.cnblogs.com/Iqiaoxun/p/6195423.html