论坛首页 入门技术论坛

读取Structs properties文件

浏览 2229 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-01-06  
在这里我直接返回的是Properties对象
这样更灵活 可以在外部调用的时候想哪到Properties文件里的哪个属性都行,当然必须要是Properties里存在的。。。


   /**
	 * 读取properties文件 
	 * @param propertiesname
	 * @return
	 */
	public static Properties getProperties(String propertiesname) {
		Map map=new HashMap();
		Properties prop=null;
		try {
			InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(propertiesname);
			prop = new Properties();
			prop.load(in);
			in.close();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return prop;
	}


public static void main(String args[]) {
		
		Map map=null;
		Properties prop=Htools.getProperties("imageurl.properties");
		String url=prop.getProperty("imgurl").toString();
		String aa=prop.getProperty("country").toString();
                  //这里是为了解决读取中文的问题
		try {
			aa=new String(aa.getBytes("ISO8859_1"),   "GBK");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		System.out.println(url+"-----"+aa);
		
	}
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics