java读取properties文件工具

public class PropertiesUtil {

    public static String get(String filePath, String key) {
        String val = null;
        Properties prop = new Properties();
        InputStream in = null;
        in = PropertiesUtil.class.getClassLoader().getResourceAsStream(filePath);
        try {
            prop.load(in);
            val = (String) prop.get(key);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return val;
    }
}

 

posted @ 2016-10-20 19:44  豆苗稀  阅读(122)  评论(0编辑  收藏  举报