test.properties
className = Reflection.Student
methodName = show
test.txt
className = Reflection.Student
methodName = show
package Reflection;
public class Student {
public void show(){
System.out.println("hhh");
}
public void show(String s){
System.out.println(s);
}
}
package Reflection;
import java.lang.reflect.Method;
import java.util.Properties;
public class ReflectFile {
public static void main(String[] args) throws Exception{
Properties pro=new Properties();
pro.load(ReflectFile.class.getClassLoader().getResourceAsStream("test.properties"));
String forName=pro.getProperty("className");
Class stuClass=Class.forName(forName);
String methodName=pro.getProperty("methodName");
Method m=stuClass.getMethod(methodName);
m.invoke(stuClass.getConstructor().newInstance(),null);
methodName=pro.getProperty("methodName");
m=stuClass.getMethod(methodName,String.class);
m.invoke(stuClass.getConstructor().newInstance(),"null");
}
}