创建properties的时候注意位置,要创建到根目录下才可访问到
public Person doMakePerson(){
//准备配置文件对象
Properties properties = new Properties();
//读取配置文件
InputStream resourceAsStream = MarkPersonFactoryThree.class.getClassLoader().getResourceAsStream("person.properties");
System.out.println(resourceAsStream);
try {
properties.load(resourceAsStream);
//获得对应的value
String fullClassName = properties.getProperty("chinese");
//通过反射创建对应的对象
Class<?> aClass=Class.forName(fullClassName);
return (Person) aClass.newInstance();
} catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
return null;
}