java後臺讀取配置文件中key與value -----demo
阿新 • • 發佈:2017-05-11
undle ltm string 文件名 logs 配置 rip conf 返回值
public class ResourcesUtils { /* * @description:根據屬性獲取文件名 * * @param:propertyName文件的屬性名 * * @return:返回文件的屬性值 * */ public static String getByName( String propertyName) { String resultM = "";//返回結果 ResourceBundle bundle = ResourceBundle.getBundle("config");//獲取config的熟悉 if (bundle.containsKey(propertyName)){//包含屬性的key就返回相應的值 resultM = bundle.getString(propertyName);//設置返回值 } return resultM; } /* * @description:根據屬性獲取文件名 * * @param:propertyName文件的屬性名 * * @return:返回文件的屬性值 * */ public static String getByName( String propertyName, String propertyFile) { String resultM = "";//返回結果 ResourceBundle bundle = ResourceBundle.getBundle(propertyFile);//獲取config的熟悉 if (bundle.containsKey(propertyName)){//包含屬性的key就返回相應的值 resultM = bundle.getString(propertyName);//設置返回值 } return resultM; } }
配置文件中的內容:
java後臺讀取配置文件中key與value -----demo