读取Properties文件工具类

代码如下:

/**
 * 读取properties文件公共类
 * @author jw
 *
 */
public class PublicGC {

	
  private   static ResourceBundle loadProperties(String configfilename)
    {
        return ResourceBundle.getBundle(configfilename,Locale.getDefault());
    }

  /**
   * 
   * @param configfilename
   * @param name
   * @param defaultValue
   * @return
   */
    public static String getString(String configfilename ,String name  ,String defaultValue)
    {
        ResourceBundle resources =loadProperties( configfilename );
        if (name == null) {
            return null;
        }
        try {
            return  resources.getString(name).trim();
        } catch(Exception ex){
            return  defaultValue;
        }
    }
    public static void main(String []args)
    {
    	String exportFileUrl = PublicGC.getString("platform", "exportFileUrl", "data");
    	// 替换占位符
		exportFileUrl = MessageFormat.format(exportFileUrl, DateUtils.getYMD());
    	System.err.println(exportFileUrl);
    }

}

你可能感兴趣的:(properties)