java中获得properties配置文件中的值的写法

import java.util.Properties;

class PropertyUtil extends Properties{

private static final long serialVersionUID = 1L;

public static Properties pp;

public static String getValue(String key) throws IOException{

if(pp == null){

pp = new Properties();

}

InputStream is = Properties.class.getResourceAsStream("/struts_properties/value.properties"); //获得流资源

pp.load(is);//装载

return pp.getProperty(key); //得值

}

==========================================struts2 环境下获得properties 属性的方法

if(pp == null){

pp = new Properties();

}

ActionContext ac = ActionContext.getContext();

ServletContext sc = (ServletContext) ac.get(ServletActionContext.SERVLET_CONTEXT);

InputStream is = sc.getResourceAsStream("WEB-INF/classes/net.properties");

pp.load(is);//装载

String s = pp.getProperty("net");

if("gaw".equals(s)){

return true;

}else{

return false;

}