ResourceBundle读取配置文件

来源:互联网 发布:jdbc连接db2数据库 编辑:程序博客网 时间:2024/06/08 02:41

1. 在Java语言中,使用类似config.properties这样的文本文件作为资源文件


2. 在后端代码 类中获取config.properties中的内容:(下面的类是单例模式)

    private static String Type;
    static {
        res = ResourceBundle.getBundle("conf/config"); //获取config.properties文件
        MSECOND = Integer.valueOf(resource.getString("MAX_SECOND")); //获取config.properties文件中的MAX_SECOND的值
    }


3. 或者如下:

    static {
        Properties props = null;
        try {
            props = PropertiesLoaderUtils.loadAllProperties("conf/rpc.properties");
            BASE_URL = props.get("BaseInfo").toString();
            SERVICE_NEW_URL = props.get("Service").toString();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


0 0
原创粉丝点击