读取配置文件 ( properties ) 中的数据

java代码

public class Reflex {
    public static void main(String[] args) throws Exception {
        Properties pro = new Properties();
        ClassLoader classLoader = Reflex.class.getClassLoader();
        InputStream resourceAsStream = classLoader.getResourceAsStream("application.properties");
        pro.load(resourceAsStream);

        String className = pro.getProperty("className");
        String methodName = pro.getProperty("methodName");
    }

}

 application.properties

className=com.xz.test2.Person
methodName=eat

 

posted @ 2021-03-10 09:45  zagwk  阅读(73)  评论(0编辑  收藏  举报