网上各处搜索的资源,我知道有两种方法:
1。通过request方式
request.getSession().getServletContext().getRealPath("/");
2。通过spring包
01 | import org.springframework.core.io.Resource; |
03 | import org.springframework.core.io.ClassPathResource; |
05 | //前提仍然是要将properties文件放在src下 |
07 | Resource resource = new ClassPathResource( "xxx.properties" ); |
09 | props = new Properties(); |
11 | InputStream in = resource.getInputStream(); |
13 | props.load(in); |
第二种方式来自:http://www.2016k.com/java/05-30.html