Idea SpringMVC项目读取.properties文件

 

 

            目录文件如下:

                                

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

0=success
100=邮箱错误
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");
    }
}

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值