1. 程式人生 > >讀取配置文件工具demo

讀取配置文件工具demo

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