首页 > 代码库 > 放射及properties文件读取

放射及properties文件读取

package com.forname;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class User {

    public void ff(){
        System.out.println("User.ff()");
    }
    
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
        //反射获取类
        Class u=Class.forName("com.forname.User");
        User uu=(User) u.newInstance();
        uu.ff();
        
        
        //读取properties文件
        InputStream in=User.class.getClassLoader().getResourceAsStream("db.properties");
        
        Properties p=new Properties();
        p.load(in);
        
        System.out.println(p.get("user"));
        System.out.println(p.get("name"));
        System.out.println(p.get("sex"));
    }
}

 

放射及properties文件读取