- 创建properties对象
Properties properties = new Properties();
- 获取类加载器
ClassLoader classLoader = ReflectTest.class.getClassLoader();
- 将对应的配置文件加载到properties对象中
InputStream stream = classLoader.getResourceAsStream("pro.properties");
properties.load(stream);
- 现在就可以获取properties配置文件中的值了
String className = properties.getProperty("className");
String methodName = properties.getProperty("methodName");
- 完整代码
Properties properties = new Properties();
ClassLoader classLoader = ReflectTest.class.getClassLoader();
InputStream stream = classLoader.getResourceAsStream("pro.properties");
properties.load(stream);
String className = properties.getProperty("className");
String methodName = properties.getProperty("methodName");