1、Properties
(1)通过资源包ResourceBundle获得资源对象
<pre name="code" class="java">public class PropertiesTest { public static HashMap<String, Properties> hashMap = new HashMap<String, Properties>(); public static String filename = "my"; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ResourceBundle bundle = ResourceBundle.getBundle("my"); Properties properties = new Properties(); Enumeration<String> enumeration = bundle.getKeys(); while (enumeration.hasMoreElements()) { String key = enumeration.nextElement(); String value = bundle.getString(key); properties.put(key, value); } hashMap.put(filename, properties); Properties properties2 = hashMap.get(filename); Enumeration<Object> enumeration2 = properties2.keys(); while (enumeration2.hasMoreElements()) { String key = (String) enumeration2.nextElement(); String value1 = properties2.getProperty(key); try { String value2 = new String(value1.getBytes("ISO8859-1"), "UTF-8"); System.out.println("key-->" + new String(key.getBytes("ISO8859-1"), "UTF-8") + " value-->" + value2); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
InputStream inputStream = getClass().getResourceAsStream( "/my.properties"); Properties properties = new Properties(); try { properties.load(inputStream); Enumeration<Object> enumeration = properties.keys(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); String value = properties.getProperty(key); System.out.println(new String(key.getBytes("ISO8859-1"), "utf-8") + ";" + new String(value.getBytes("ISO8859-1"), "utf-8")); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
原文地址:http://blog.csdn.net/scboyhj__/article/details/39889145