1.java工具类中获取resources下面的文件夹下面的文件路径。例如resources/img/logo.png。
1 | SendMailUtil.class.getClassLoader().getResource("img/logo.png").getPath() |
输出结果:/D:/gitLocalRepo/innerManage/fmInnerManage/out/production/resources/img/logo.png
2.获取java工具类中classpath(class文件的路径)。
1 | System.out.println(Class.class.getClass().getResource("/img/logo.png").getPath()); |
/D:/gitLocalRepo/innerManage/fmInnerManage/out/production/resources/img/logo.png
file:/D:/gitLocalRepo/innerManage/fmInnerManage/out/production/resources/img/logo.png
file:/D:/gitLocalRepo/innerManage/fmInnerManage/out/production/resources/img/logo.png
file:/D:/gitLocalRepo/innerManage/fmInnerManage/out/production/classes/
file:/D:/gitLocalRepo/innerManage/fmInnerManage/out/production/classes/com/ynet/finmall/innermanage/utils/
file:/D:/gitLocalRepo/innerManage/fmInnerManage/out/production/classes/