java修改配置文件参数_在java类中获取在.properties配置文件中设置的参数

如何获取.properties配置文件中的参数,我在网上查了半天没弄明白,后来在以前的项目中找到了,就写下来,避免遗忘。

1.配置文件:message_product.properties

total_product=2

service1=1,新股发行短信提醒服务,发行的详细信息

service2=2,配股短信提醒服务&增发短信提醒服务,增发的详细信息

validatecode_temp=验证码:${vilidateCode}。

#消息持续发送时间,单位”小时“

message_constant_time=24

#消息的编码格式 15 GBK编码 30 彩信 31 wappush 32 长短信 33个性彩信'

message_formart=15

#'消息的优先级: 0 最低 --- 3 最高';

message_priority=3

#'消息的下发类型: 0 免费下发 1 按条下发 2 包月下发 3 订阅请求 4 取消请求 5 包月扣费';

message_type=0

#产品ID numproductid

message_product_id=724

#numchannelid

message_channelid=0

2.java 类

package com.margin.utils;

import java.io.UnsupportedEncodingException;

import java.util.ResourceBundle;

import com.margin.po.MessageProduct;

public class MessageProperties {

private static ResourceBundle rb;

static {

rb = ResourceBundle.getBundle("message_product");

}

/**

* 得到短信服务总数

* @return

*/

public static int getTotalProduct() {

return Integer.parseInt(rb.getString("total_product"));

}

/**

* 消息持续发送时间

* @return

*/

public static int getMessageConstantTime()

{

return Integer.parseInt(rb.getString("message_constant_time").trim());

}

/**

* 消息格式

* @return

*/

public static int getMessageFormat()

{

return Integer.parseInt(rb.getString("message_formart").trim());

}

/**

* 消息发送优先级

* @return

*/

public static int getMessagePriority()

{

return Integer.parseInt(rb.getString("message_priority").trim());

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值