1. 程式人生 > >java後臺讀取配置文件中key與value -----demo

java後臺讀取配置文件中key與value -----demo

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