web工程读取配置文件的几种方式
配置文件配置在WebContent目录下
第一种:获取资源在tomcat里面的绝对路径
- 获取WebContent/properties/config.properties文件信息
通过ServletContext获取绝对路径
//这里得到的是项目在tomcat里面的根目录。
context.getRealPath("");
// D:\Java\tomcat\tomcat-7.0.86\wtpwebapps\learn_servlet01
String path = context.getRealPath("properties/config.properties"