美文网首页java
java后台中使用resources中的properties文件

java后台中使用resources中的properties文件

作者: 揪个太阳 | 来源:发表于2017-09-19 18:01 被阅读3次

    每次用总是忘,在这里记录一下。

    properties文件放在src/main/resources中,访问代码:

    /**

    * 从properties中读取属性数据

    * @param tag

    * @return

    */

    public static String getFromProperties(String tag)

    {

    //读取属性数据

    Properties props = new Properties();

    String res="";

    {

    try {

    props.load(Wechat.class.getClassLoader().getResourceAsStream(propertiesAdd));

    res=props.getProperty(tag);

    } catch (FileNotFoundException e) {

    e.printStackTrace();

    System.exit(-1);

    } catch (IOException e) {

    System.exit(-1);

    }

    }

    return res;

    }

    相关文章

      网友评论

        本文标题:java后台中使用resources中的properties文件

        本文链接:https://www.haomeiwen.com/subject/klhgsxtx.html