JAVA加載配置文件,並按鍵值取值

import java.io.InputStreamReader;
import java.util.Properties;

public class getValueUtil {
	
	static Properties prop = new Properties();
	
	public static String getProperty(String keyString){
		if(prop.size() == 0){
			try {
				prop.load(new InputStreamReader(getValueUtil.class.getClassLoader().getResourceAsStream("settings.properties"), "UTF-8"));
			} catch (Exception ex) {
				//do something
			}
		}
		return prop.getProperty(keyString);
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章