package cn.my.utils;
import java.util.Properties;
/**
* 查询Properties 文件 key值@date 2014.10.15
* @author wangbowen
* @version 1.0
*
*/
public class PropertiesUtil{
private static Properties properties;
/**
* 根据KEY,读取文件对应的值
* @param filePath 文件路径,即文件所在包的路径,例如:java/util/config.properties
* @param key 键
* @return key对应的值
*/
public static String findData(String file, String key) {
try {
if(file!=null){
properties = new Properties();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
properties.load(classLoader.getResourceAsStream(file));
}
String value = properties.getProperty(key);
return value;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
java读取Properties文件的工具类
最新推荐文章于 2023-06-03 20:33:29 发布