文件路径

String path = 类名.class.getClassLoader().getResource("xml").getPath();

1、xxx.class.getClassLoader().getResource(“”).getPath(); 获取src资源文件编译后的路径(即classes路径)

2、xxx.class.getClassLoader().getResource(“文件”).getPath(); 获取classes路径下“文件”的路径

3、xxx.class.getResource(“”).getPath(); 缺少类加载器,获取xxx类经编译后的xxx.class路径

4、this.getClass().getClassLoader().getResource(“”).getPath(); 以上三种方法的另外一种写法

5、request().getSession().getServletContext().getRealPath(“”);

原文地址:https://www.cnblogs.com/lingcheng7777/p/11645808.html