Properties的load方法其实就是传进去一个输入流,字节流或者字符流,字节流利用InputStreamReader转化为字符流,
然后字符流用BufferedReader包装,BufferedReader读取properties配置文件
每次读取一行,分割成两个字符串。因为Properties是Map的子类
然后用put将两个字符串装进Properties对象。
- package com.xiaozhi.helloio;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.util.Properties;
- public class Test7 {
- public static void main(String[] args) throws IOException {
- Properties properties=new Properties();
- properties.load(new FileInputStream("c:\xiaozhi.properties"));
- System.out.println(properties.getProperty("lisi"));
- System.out.println(properties.getProperty("zhangsan"));
- }
- }