ResourceBundle类的使用_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > ResourceBundle类的使用

ResourceBundle类的使用

 2015/1/7 12:47:23  lihongtai  程序员俱乐部  我要评论(0)
  • 摘要:packagecn.newtouch.test;importjava.util.Enumeration;importjava.util.HashMap;importjava.util.Iterator;importjava.util.Map;importjava.util.MissingResourceException;importjava.util.ResourceBundle;publicclassTestStringSplit{/**TheConstantregistry
  • 标签:
class="java" name="code">package cn.newtouch.test;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class TestStringSplit {

	/** The Constant registry. */
	private static final Map<String, Map<String, String>> REGISTRY = new HashMap<String, Map<String, String>>();

	/** The separator add in mandate-135. */
	private static String separator = "??";

	public static void main(String[] args) {
		String line= "5438??VEH??VF7BU9HD8EZ902714??CITROEN TALLER??CITROEN C4??1CMJSUPBMK04A030M6E59JFX??20131230??E 3872 HVF??15000??20141111??????????DMS";
		cutLine(line, registryResource("vehDto"));
	}

	public static Map<String, String> registryResource(String propertyFileName) {
		Map<String, String> properties = REGISTRY.get(propertyFileName);
		if (properties == null) {
			ResourceBundle rb = null;
			try {
				rb = ResourceBundle.getBundle(propertyFileName);
			} catch (MissingResourceException e) {
				rb = ResourceBundle.getBundle(propertyFileName.toLowerCase());
			}
			properties = new HashMap<String, String>();
			Enumeration<String> cles = rb.getKeys();
			while (cles.hasMoreElements()) {
				String cle = cles.nextElement();
				String bornes = rb.getString(cle);
				properties.put(cle, bornes);
			}
			REGISTRY.put(propertyFileName, properties);
		}
		return properties;
	}

	public static Map<String, String> cutLine(String line, Map<String, String> cutlineProperties) {
		Map<String, String> properties = new HashMap<String, String>();
		Iterator<String> cles = cutlineProperties.keySet().iterator();
		String[] lines = line.split(separator);
		int index = -1;
		while (cles.hasNext()) {
			String cle = cles.next();
			index = Integer.valueOf(cutlineProperties.get(cle));
			if (index < lines.length) {
				properties.put(cle, lines[index]);
			} else {
				properties.put(cle, null);
			}
		}
		return properties;
	}
}

?

  • 大小: 76.3 KB
  • 大小: 32 KB
  • 查看图片附件
  • 相关文章
发表评论
用户名: 匿名