標籤:屬性 res 傳回值 blog resources val logs com pre
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