IO+Properties

public class Test01 {
    public static void main(String[] args) throws Exception {
        //1.创建属性对象
        Properties p=new Properties(); //和Map一样,只不过key和value只能存储字符串类型,key不能重复,如果key重复则value覆盖。
        
        //2.创建输入流
        FileInputStream fis=new FileInputStream("E:/core/javabase/src/main/resources/db.properties");
        
        //3.将fis流中的所有数据 加载到属性对象中
        p.load(fis);
        
        //4.关闭流
        fis.close();
        
        //通过key获取value
        String v=p.getProperty("username");
        
        System.out.println(v);
        
    }
}

posted @ 2019-11-10 15:09  田园沃土  阅读(130)  评论(0编辑  收藏  举报