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("")); } }