IO和Properties

需求:

把文件中的数据(键值对的形式)加载到内存,存到Properties对象中。

jdbc.properties文件

username=gao
password=123
package cn.donglinode.IO;

import java.io.FileReader;
import java.util.Properties;

public class IOPropertiesDemo01 {
    public static void main(String[] args) throws Exception {
        FileReader reader=new FileReader("chapter16/src/properties/jdbc.properties");
        Properties pro=new Properties();
        pro.load(reader);
        System.out.println(pro.getProperty("username"));
        System.out.println(pro.getProperty("password"));

    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章