【Properties】Properties的load方法

Properties的load方法其实就是传进去一个输入流,字节流或者字符流,字节流利用InputStreamReader转化为字符流,

 

然后字符流用BufferedReader包装,BufferedReader读取properties配置文件

 

每次读取一行,分割成两个字符串。因为Properties是Map的子类

 

然后用put将两个字符串装进Properties对象。

 

 

 

[java] view plain copy
 
 print?
  1. package com.xiaozhi.helloio;  
  2.   
  3. import java.io.FileInputStream;  
  4. import java.io.IOException;  
  5. import java.util.Properties;  
  6.   
  7. public class Test7 {  
  8.   
  9.     public static void main(String[] args) throws IOException {  
  10.         Properties properties=new Properties();  
  11.         properties.load(new FileInputStream("c:\\xiaozhi.properties"));  
  12.         System.out.println(properties.getProperty("lisi"));  
  13.         System.out.println(properties.getProperty("zhangsan"));  
  14.     }  
  15. }  
posted @ 2017-03-15 23:55  Faron  阅读(2164)  评论(0编辑  收藏  举报