讀取配置文件工具demo
阿新 • • 發佈:2017-08-13
utils java resource get log dem bundle gets per
//讀取配置文件
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; } }
讀取配置文件工具demo