Idea SpringMVC项目读取.properties文件

来源:互联网 发布:php支付系统源码 2016 编辑:程序博客网 时间:2024/05/21 17:11



            目录文件如下:

                                

               我们是使用代码得到errorCode.properties中的文件内容:

0=success100=邮箱错误101=密码错误102=此邮箱已被注册103=两次密码输入不一致104=登录失效,请重新登陆105=旧密码错误200=创建成功201=获取失败,请重新登录202=创建失败203=删除成功204=删除失败205=修改成功206=修改失败300=登录失效,请重新登录301=分享成功302=删除分享成功303=得到用户分享列表304=得到计划圈分享列表失败400=获取列表成功401=分享为空501=评论列表为空502=加载失败503=评论失败602=找不到此计划603=参加人数超过最大人数601=你已经加入了此计划604=参加人数已经达到最大人数305=该计划已被分享605=没有权限操作606=你没有加入该计划

package com.imudges.utils;/** * Created by Administrator on 2016/12/10. */import java.io.IOException;import java.io.InputStream;import java.util.Properties;public class Information {    static private Information instance;    private Information() {        // TODO Auto-generated constructor stub    }    static public Information getInstance() {        if(instance == null)            instance = new Information();        return instance;    }    public String getErrorInfo(int errorCode) {        Properties properties = new Properties();        InputStream in = this.getClass().getResourceAsStream("/errorCode.properties");        try {            properties.load(in);        } catch (IOException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }        return properties.getProperty(errorCode + "", "null");    }    public String getConfigInfo(String param){        Properties properties = new Properties();        InputStream in = this.getClass().getResourceAsStream("/config.properties");        try {            properties.load(in);        } catch (IOException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }        return properties.getProperty(param, "null");    }}


0 0
原创粉丝点击