zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    动手动脑3
    AWK编程与应用
    BASH内置变量的使用
    服务器交互脚本expect
    编程对话框的界面程序
    每日打卡
    AppiumLibrary中文翻译
    Bootstrap4简单使用
    Python基础06-类与对象
    BDD模式-Python behave的简单使用
  • 原文地址:https://www.cnblogs.com/leonkobe/p/3309945.html
Copyright © 2011-2022 走看看