1 配置.properties文件
2 獲取輸入流的方法
1)FileInputStream fi = new FileInputStream(properties文件路徑);
2)InputStream fis = 類名.class.getClassLoader().getResourceAsStream(properties文件名);
3 Properties類中常用的方法
1).load ( InputStream inStream) ,從輸入流中讀取屬性列表(鍵和元素對)。通過對指定的文件(比如說上面的 test.properties 文件)進行裝載來獲
2).getProperty ( String key) , 用指定的鍵在此屬性列表中搜索屬性。也就是通過參數 key ,得到 key 所對應的 value。
取該文件中的所有鍵 - 值對。以供 getProperty ( String key) 來搜索。
3).setProperty ( String key, String value) ,調用 Hashtable 的方法 put 。他通過調用基類的put方法來設置 鍵 - 值對。
4).store ( OutputStream out, String comments) , 以適合使用 load 方法加載到 Properties 表中的格式,將此 Properties 表中的屬性列表(鍵和元素對)寫入輸出流。與 load 方法相反,該方法將鍵 - 值對寫入到指定的文件中去。
5).clear () ,清除所有裝載的 鍵 - 值對。該方法在基類中提供。