为啥我反射他会报错,文件路径错了嘛
应该学成啥啊
package reflection;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;
public class reflection {
public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
Properties properties=new Properties();
properties.load(new FileInputStream("src\\hello.txt"));
String classfullpath=properties.get("classfullpath").toString();
String method=properties.get("method").toString();
System.out.println(classfullpath);
System.out.println(method);
Class cls=Class.forName(classfullpath);
Object o=cls.newInstance();
System.out.println(o.getClass());
Method method1= cls.getMethod(method);
method1.invoke(o);
}
public class cat{
private String name="招财猫";
public void hi(){
System.out.println("hi"+name);
}
public void cry(){
System.out.println(name+"喵喵叫");
}
}
}