package com.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* @Auther: wjc
* @Date: 2018/10/23
* @Description: properties文件读取工具类
*/
public class PropertiesUtils {
private static final Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);
/**
* 读取properties文件的信息
* 相对路径,properties文件需在classpath目录下
* getProperty(String key) 获取属性
* @param propertiesName
*/
public static Properties getObject(String propertiesName) {
InputStream in = PropertiesUtils.class.getClassLoader().getResourceAsStream(propertiesName);
Properties prop = new Properties();
try {
prop.load(in);
} catch (IOException e) {
logger.error(e.getMessage(),e);
} finally {
try {
if(null != in){
in.close();
}
} catch (IOException e) {
logger.error(e.getMessage(),e);
}
}
return prop;
}
}