1. 程式人生 > >java中讀取Property檔案屬性工具類

java中讀取Property檔案屬性工具類

java中讀取Property配置檔案屬性工具類:

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * 讀取Property配置檔案屬性工具類
 */
public class PropertyUtil {
	
	//讀取配置檔案
	public static String getValue(String key){
		String value = "";
		Locale locale = Locale.getDefault();
		try {
			ResourceBundle localResource = ResourceBundle.getBundle("wzy",
					locale);
			value = localResource.getString(key);
		} catch (MissingResourceException mre) {
			value = "";
		}
		return value;
	}
	
}