java的properties类
java的properties类多用于灵活配置文件,避免硬编码。
一般配置文件放在conf目录下,创建conf目录进行source加载。创建file文件
demo:
public static Properties loadPro(String fileName){//只传文件名即可
Properties pro=new Properties();
//类名.构造输入流
InputStream inputStream = properties_Test.class.getClassLoader().getResourceAsStream(fileName);
//调用load完成文件加载
try {
pro.load(new InputStreamReader(inputStream,"UTF-8"));
} catch (IOException e) {
e.printStackTrace();
}
return pro;
}