获取classpath(src/main/resources)的绝对路径

先贴上代码

private static String basePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();

原因:方法是通过线程去执行的,因此我们可以通过线程去逆推到类加载器,从而在这个类加载器得到资源的路径。

猜你喜欢

转载自blog.csdn.net/hyx1249273846/article/details/113726700