- package com.wxy001;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.lang.reflect.Method;
- import java.util.Properties;
- public class RefelecTest10
- {
- public static void main(String[] args) throws Exception
- {
- // InputStream read = RefelecTest10.class.getResourceAsStream("/exam/src/com/wxy001/prop.properties");
- FileReader read = new FileReader("D:/java/eclipser-WTP/exam/src/com/wxy001/prop.properties");
- Properties prop = new Properties();
- prop.load(read);
- read.close();
- String className = prop.getProperty("name");
- System.out.println(className);
- Class<?> clazz = Class.forName(className);
- Object obj = clazz.newInstance();
- Method m = clazz.getMethod("run");
- m.invoke(obj);
-
-
-
- }
- }
- class Demo
- {
- public void run()
- {
- System.out.println("run() method has been invoked");
- }
- }
复制代码
配置文件:prop.properties
name=com.wxy001.Demo |
|