package com.ule.util;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
public class PropertiesUtils {
/**
* (注意:加载的是src下的文件,如果在某个包下.请把包名加上)
* @return
*/
public static Properties getProperties(String sourcesFileName){
Properties properties = new Properties();
String savePath = Thread.currentThread().getContextClassLoader().getResource(sourcesFileName).getPath();
try{
InputStream inputStream = new BufferedInputStream(new FileInputStream(savePath));
properties.load(inputStream);
}catch (Exception e){
e.printStackTrace();
}
return properties;
}
/**
* 获取属性文件的数据 根据key获取值
* @param key
* @return
*/
public static String findPorpertyByKey(String key,String sourcesFileName){
try {
Properties pro = getProperties(sourcesFileName);
return pro.getProperty(key);
}catch (Exception e){
return "";
}
}
}
读取properties配置文件工具类
最新推荐文章于 2022-06-28 00:00:02 发布