import java.io.InputStream;
import java.util.Properties;
/**
* 属性文件操作类
*
*/
public class PropertyUtils {
private final static String FILE_NAME = "config.properties";
private static Properties property = null;
private PropertyUtils(){
}
static{
if(null == property){
property = new Properties();
}
try {
//读取src目录下的配置文件
InputStream is = PropertyUtils.class.getClassLoader().getResourceAsStream(FILE_NAME);
//读取PropertyUtils.java所在文件夹下的配置文件
//InputStream is = PropertyUtils.class.getResourceAsStream(FILE_NAME);
property.load(is);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getProperty(String key){
return property.getProperty(key);
}
}
读取配置文件随记
最新推荐文章于 2025-01-27 22:01:02 发布