反射在实际开发中的应用
properties:属性文件
文件中的内容:以键值对的形式存在
键和值都是以字符串的形式存在
clas.properties:
username = root
password=root
className = org.lanqiao.reflect.demo.Student
package org.lanqiao.reflect.demo2;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class TestPro {
public static void main(String[] args) throws IOException {
//创建properties对象
Properties pro = new Properties();
//以流的形式加载属性配置文件
//InputStream is = new FileInputStream(new File("clas.properties"));
//通过类加载器来获取配置文件的输入流
InputStream is = TestPro.class.getClassLoader().getResourceAsStream("clas.properties");
pro.load(is