码迷,mamicode.com
首页 > 编程语言 > 详细

java.util.ResourceBundle学习笔记

时间:2014-11-04 17:11:13      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   使用   java   文件   on   art   

初次使用,从网上查的资料,知识点参考JDK API和博文http://lavasoft.blog.51cto.com/62575/184605(该博主写的清晰易懂)

自己在程序中的具体应用:

  1. ①src下建立文件test.properties,其中内容:name=google
  2. ②java程序中:
    /**
     * 根据配置文件中的值,设置url路径
     * @param propertiesFileName 配置文件的文件名
     * @param itemName 读取的配置文件中的key的值
     * @return url路径
     */
    public static String getPath(String propertiesFileName, String itemName){
        String path = "";
        try{
            ResourceBundle resources = ResourceBundle.getBundle(propertiesFileName);
            String itemValue = resources.getString(itemName);
            if(("google").equals(itemValue.substring(0, 4))){
            	path="www.google.com.hk";
    		}else if(("baidu").equals(itemValue.substring(0, 4))){
    			path="www.baidu.com";
    		}else{
    			path="www.bing.com";
    		}
        }
        catch(Exception e){
        	path="www.bing.com";
        	e.printStackTrace();
        }
        return path;
    }

③调用的时候,getPath("test.properties","name");返回:"www.google.com.hk"

待续……

java.util.ResourceBundle学习笔记

标签:blog   http   io   ar   使用   java   文件   on   art   

原文地址:http://www.cnblogs.com/mySummer/p/4073742.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!