网上各处搜索的资源,我知道有两种方法:
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
本文介绍如何利用Spring框架加载并使用配置文件,通过两种方法实现:一种是通过request方式获取真实路径;另一种则是利用Spring提供的ClassPathResource类简化操作。文章详细解释了两种方法的实现步骤及应用场景。
558

被折叠的 条评论
为什么被折叠?



