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;
    }
  • 相关阅读:
    Tomcat常用配置
    java开发规范总结_命名规范
    Android学习笔记(广播机制)
    Java Web 实现Mysql 数据库备份与还原
    interfaces
    windows phone 1
    正在写。。
    Exceptions
    类的非常简单的应用
    say hello
  • 原文地址:https://www.cnblogs.com/leonkobe/p/3309945.html
Copyright © 2011-2022 走看看