1. Properties
(1) Obtaining resource objects through resource bundle ResourceBundle
<pre name= "code" class= "Java" >public class Propertiestest {public static hashmap<string, properties> HashMap = new hashmap<string, properties> ();p ublic static String filename = "my";/** * @param args */public static V OID Main (string[] args) {//TODO auto-generated method Stubresourcebundle 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);p roperties.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 Blocke.printstacktrace ();}}}
(2) Obtaining a resource object from an input stream
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 Blocke.printstacktrace ();}
Basic Java Knowledge