(1) 写一个 Properties 格式的配置文件,配置类的完整名称。 * (2) 写一个程序,读取这个 Properties 配置文件,获得类的完整名称并加载这个类,用 反射 的方式运行
2016-04-12 23:02
881 查看
package com.heima.test; 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 Test7 { /**题目: * (1) 写一个 Properties 格式的配置文件,配置类的完整名称。 * (2) 写一个程序,读取这个 Properties 配置文件,获得类的完整名称并加载这个类,用 反射 的方式运行 run 方法 * @param args * @throws IOException * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException * @throws SecurityException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalArgumentException */ public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException { FileInputStream fis = new FileInputStream("properties"); Properties pp = new Properties(); pp.load(fis); String str = pp.getProperty("className"); Class clazz = Class.forName(str); Object obj = clazz.newInstance(); Method me = clazz.getMethod("run", null); me.invoke(obj, null); } }
相关文章推荐
- win系统cmd运行Linux命令
- 一个opencv 博客 大量文章(老版本编写C )
- epel扩展源(转)
- centos 火狐浏览器安装adobe flash player插件
- JDK环境变量配置及Tomcat安装服务
- 1.5-docker基于本地模板创建镜像
- php千万级pv架构经验分享
- 1.4-docker镜像使用容器生成新的镜像
- 1.3-docker镜像管理
- 1.2-docker安装
- linux -- Fedora安装TFTP服务器
- linux定时任务2-at命令
- 1.1-docker简介
- Bitnami的WAMP服务套件安装
- Visual Studio 2015 开发 Linux 和树莓派 程序的 C++环境
- Linux环境下安装JDK
- POJ 3641 Pseudoprime numbers
- 文件监控
- Linux之关键目录集锦
- Linux Command -- sed