java代码读取properties文件

来源:互联网 发布:深度思考 知乎 编辑:程序博客网 时间:2024/06/02 06:34
package com.glbk.hec.util;import java.io.IOException;import java.io.InputStream;import java.util.Properties;/** * Created by shuai on 2017/4/19. * 读取配置文件 */public class GetProperties {    private static Properties prop = null;    static{        prop = new Properties();        //设置properties文件路径,以src为根路径(config.properties 处于src根目录下)        InputStream in = GetProperties.class.getResourceAsStream("errorCode.properties");        try {            prop.load(in);        } catch (IOException e) {            System.out.println("读取配置文件失败---->>>>----(/src/config.properties)");            e.printStackTrace();        }    }    /**     * 根据传入的KEY获取配置文件中对应的值     * @param key     * @return     */    public static String getPropertieValue(String key){        String value = "";        value = prop.getProperty(key).trim();        return value;    }    public static void main(String[] args) {   String a="a";   Integer.parseInt(a);    }}

原创粉丝点击