`
bei-jin-520
  • 浏览: 108593 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

读取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);
    }

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics