Java讀取properties配置檔案的方式
一.背景
二.代碼片段
三.完整工具類代碼
Java讀取 properties 配置檔案的方式,主要是通過 getProperty() 方法。config.properties 檔案中有諸如 config.a = xxx 這樣的存儲形式,下面代碼是讀取 properties 配置檔案中參數資料到 String 類型變量中。
readProperties 方法中的參數是<code>.properties</code>配置檔案的相對路徑,比如<code>src/main/resources</code>,getkey 方法用來依據鍵取出值
<code>.properteis</code>檔案内容怎麼寫呢?如下: