读取properties文件, 比如获得税率,提示等信息

1 篇文章 0 订阅
1 篇文章 0 订阅

读取properties文件, 比如获得税率,提示等信息

package com.appbox.util.property;

import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class PropertiesUtil {


	//根据key读取value
	private static Logger log = Logger.getLogger(PropertiesUtil.class.getName());
	/**
	 * 默认配置文件名称
	 */
	private static String defaultPropertyName="advertise.properties";
	
	
	/**
	 * 从默认的配置文件中按key取value
	 * @param key
	 * @return
	 */
	public static String getPropertyValue(String key){
		return getProperties(defaultPropertyName,key);
	}
	
	/**
	 * 
	 * @param filePath property的文件名字
	 * @param key  key值
	 * @return value值
	 */
	public static String getProperties(String filePath,String key){
		String value="";
		try{
			InputStream in=PropertiesUtil.class.getClassLoader().getResourceAsStream(filePath);   
			Properties p=new Properties();
			p.load(in);
            value=p.getProperty(key);
            in.close();
            p=null;
		}catch(Exception e){
			log.error("读取配置文件错误:getProperties(String filePath,String key):"+e.getMessage());
			e.printStackTrace();
		}
		return value;
	}

}

.properties文件

format.number = {0,number,0.00}
format.number2 = 101

struts.messages.error.content.type.not.allowed=上传的文件类型不符,只允许bmp,gif,jpg,png格式
struts.messages.error.file.too.large=文件上传失败,上传的文件太大  
struts.messages.error.uploading=文件上传失败,发生内部错误  
producturl=http\://lil\:8080/app/openproduct/show.action?productid\=
configroot=automake/config
templateroot=automake/template
taobaotemplate=automake/taobaotemplate
clientfileroot=automake/clientfile
sina_key=1072318004
sina_secret=2f06daa9b148d7085c0eaec6254e3204
taobao_apidomin=http\://gw.api.taobao.com/router/rest
advertisernotifymoney=100
developernotifymoney=100
idcardimagepath=idcard
invalid.fieldvalue.mediasetting.jifenrateAd=积分汇率只能为数字 
invalid.fieldvalue.mediasetting.minjifenAd=积分数量只能为整型数字
point=0.3
taxrate=0.06
point1=0.2
jifentocpa=100
pricetocpm=100
pricetocpa=10000000
pricetocpc=1000000

java中使用方法

private String idcardimagepath = PropertiesUtil.getPropertyValue("idcardimagepath");



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值