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);
}
}
资源文件读取器
最新推荐文章于 2023-08-16 08:54:42 发布