资源文件读取器


package com.ks.tools;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
* @author 李英夫
* @ClassName PropertiesLoader
* @Version
* @ModifiedBy
* @Copyright @ 2010 H&L Technology Inc.
* @date 2010-1-18 上午09:17:13
* @description 资源文件读取器
*/
public class PropertiesLoader {

//properties文件路径
private static final String PROPERTY_LOCATION = "properties/util.properties";


/**
* 根据Key找value,默认的文件路径是properties/util.properties
* @author 李英夫(2010-1-18 上午10:54:39)
* @param key
* @return
* @throws IOException String
*/
public static String getText(String key)throws IOException{
Properties props = new Properties();
String filePath = PropertiesLoader.class.getResource("/").getPath()+PROPERTY_LOCATION;
filePath = filePath.replace("%20"," ");//空格会替换掉%20,%20在路径中时,系统好像找不到啊
props.load(new FileInputStream(filePath));
return props.getProperty(key);
}

/**
* 根据Key和url找value
* @author 李英夫(2010-1-18 上午10:57:43)
* @param key
* @param url 路径
* @return
* @throws IOException String
*/
public static String getText(String key, String url)throws IOException{
Properties props = new Properties();
String filePath = PropertiesLoader.class.getResource("/").getPath()+url;
props.load(new FileInputStream(filePath));
return props.getProperty(key);
}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值