Properties 持久的屬性集

特點:
1、Hashtable的子類,map集合中的方法都可以用。
2、該集合沒有泛型。鍵值都是字符串。

3、它是一個可以持久化的屬性集。鍵值可以存儲到集合中,也可以存儲到持久化的設備(硬盤、U盤、光盤)上。鍵值的來源也可以是持久化的設備。


    // 根據key讀取value  
        public void readValue(String filePath, String key) {  
      
            Properties props = new Properties();  
      
            InputStream in = new BufferedInputStream(new FileInputStream(filePath));  
    //Thread.currentThread().getContextClassLoader().getResourceAsStream("eop.properties");  
      
            props.load(in); // 從輸入流中讀取屬性列表(鍵和元素對)  
            String value = props.getProperty(key);  
        }  
      
        // 讀取properties的全部信息  
        public static void readProperties(String filePath) {  
           Properties props = new Properties();  
           InputStream in = new BufferedInputStream(new FileInputStream(filePath));      
           props.load(in);  
      
           Enumeration en = props.propertyNames();  
            while (en.hasMoreElements()) {  
                String key = (String) en.nextElement();  
                String value = props.getProperty(key);  
          }  
        }  


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