weblogic和tomcat下通用的获取路径或者加载资源的方法

1、获取路径

this.getClass().getClassLoader().getResource("/").getPath();  //格式如...../WEB-INFO/class/

 

2、加载配置文件

若配置文件是在源文件根目录

InputString is = Thread.currentThread().getContextClassLoader().getResourceAsStream("xxxx.properties");

InputStream in = getClass().getResourceAsStream("/config.properties");//只能静态类用

相关文章: