当前位置: 代码迷 >> Web前端 >> Websphere中获取项目上.properties路径
  详细解决方案

Websphere中获取项目上.properties路径

热度:234   发布时间:2012-08-30 09:55:54.0
Websphere中获取项目下.properties路径

一:如果容器为Websphere,那下面为红色的地方不能加"/",如果为tomcat,则加上"/",

?

String  path = this.class.getResource("").getPath()+"config.properties";

Properties properties= new Properties();

properties.load(new FileInputStream(new File(path )));

?

如果你的config.properties在某个包下面,则把包同时带上,如:config.properties在com.df.util包下,则为:

String  path = this.class.getResource("").getPath()+"com/df/util/config.properties";

Properties properties= new Properties();

properties.load(new FileInputStream(new File(path )));

?

二:如果你的项目中用到了spring,那么也可这样获取,

import org.springframework.core.io.Resource;

import org.springframework.core.io.ClassPathResource;

Resource resource = new ClassPathResource("config.properties");

Properties  properties= new Properties();

InputStream in = resource.getInputStream();

properties.load(in);

??

  相关解决方案