因为是WEB环境,所以在查找文件时不能像main方法一样查找,比如写src/test.properties,在运行时时找不到的

文件路径需要改写成

xxx.class.getClassLoader() .getResource("").getPath().substring(1)

                + "test.properties"

另一种方法

private Properties pro = new Properties();

File f = new File(ContextLoader.getCurrentWebApplicationContext().getServletContext().getRealPath("/").replace("\\", "/")+"/WEB-INF/classes/test.properties");

pro.load(new FileInputStream(f));

String path= pro.getProperty("file.path");