"properties文件",是java所支持的配置文件類型.
java中的properties文件是一種配置文件,
主要用於表達配置信息,
文件類型為*.properties,
格式為文本文件,
文件的內容是格式是 "鍵=值"的格式,
在properties文件中,可以用"#"來作注釋.
"Properties類",主要用於讀取Java的配置文件.
Properties類表示一組持久的屬性。
properties屬性可以保存到流中或從流中加載。
properties屬性列表中的每個鍵及其對應的值都是一個字符串。
properties屬性列表可以包含另一個屬性列表作為其“默認值”;
如果在原始屬性列表中找不到屬性鍵,則會搜索此第二個屬性列表。
由於Properties繼承自Hashtable,所以put和putAll方法可以應用於Properties對象。
強烈地不推薦使用它們,因為它們允許調用者插入其鍵或值不是字符串的條目。
應該使用setProperty方法。
load---加載;
store--存儲;
load(Reader)/store(Writer,String)方法以一個簡單的面向行的格式從以下格式加載和存儲屬性到基於字符的流。
load(InputStream)/store(OutputStream,String)方法的工作方式與加載(Reader)/存儲(Writer,String)對相同,只是輸入/輸出流以ISO 8859-1字符編碼編碼。
public static Properties getProperties(String config) throws IOException { Properties properties = new Properties(); InputStreamReader in=null; FileInputStream inStream=null ; try { inStream = new FileInputStream(new File(config)); in = new InputStreamReader(inStream,("UTF-8")); // 處理中文字符流 properties.load(in); } catch (Exception e) { log.error("無法找到並使用配置文件: [ " + config+" ]"); } finally { if (inStream!=null) { inStream.close(); } if (in!=null) { in.close(); } } return properties; }