java 读取项目外面配置文件的方法


public static void loadProps(String propertiesUrl) {
    props = new Properties();
    InputStream in = null;
    try {
        in =new BufferedInputStream(new FileInputStream(propertiesUrl));
        props.load(in);
    } catch (FileNotFoundException e) {
        logger.error("jdbc.properties文件未找到");
    } catch (IOException e) {
        logger.error("出现IOException");
    } finally {
        try {
            if (null != in) {
                in.close();
            }
        } catch (IOException e) {
            logger.error("jdbc.properties文件流关闭出现异常");
        }
    }
    logger.debug("加载properties文件内容完成...........");
    logger.debug("properties文件内容:" + props);
}

public static String getProperty(String key) {
if (null == props) {
logger.debug("加载配置文件出错");
}
return props.getProperty(key);
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM