import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;
public class rr {
public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
FileWriter rite =new FileWriter("E://y;q.txt");
rite.write("name=ylq");
rite.flush();
FileInputStream file=new FileInputStream("E://y;q.txt");
Properties p=new Properties();
p.load(file);
String name=p.getProperty("name");
Class cass=Class.forName(name);
ylq q=(ylq)cass.newInstance();
Method method=cass.getMethod("run", null);
method.invoke(q, null);
}
}
运行时出现异常:
Exception in thread "main" java.lang.ClassNotFoundException: ylq
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at 用配置文件的方式做反射.rr.main(rr.java:20)
请问怎么解决
|
|