Copy Code code as follows:
Initialize Properties
Properties Pro = new properties ();
try {
InputStream inStr = Classloader.getsystemresourceasstream ("wahaha.properties");
Pro.load (INSTR);
catch (FileNotFoundException e) {
E.printstacktrace ();
catch (IOException e) {
E.printstacktrace ();
}
PropertyNames () Returns an enumeration of all keys in the property list
Copy Code code as follows:
Enumeration Enu2=pro.propertynames ();
while (Enu2.hasmoreelements ()) {
String key = (string) enu2.nextelement ();
SYSTEM.OUT.PRINTLN (key);
}
Returns all the property values
Copy Code code as follows:
Properties inherit from the Hashtable,elements () is the Hashtable method that returns an enumeration of the values in the hash table.
Enumeration enu=pro.elements ();
while (Enu.hasmoreelements ()) {
String key = (string) enu.nextelement ();
SYSTEM.OUT.PRINTLN (key);
}
Returns all attributes (property name, property value)
Copy Code code as follows:
Properties inherited from Hashtable,entryset () is a Hashtable method,
Returns the Set view of the keys contained in this Hashtable. Each element in this collection is a map.entry
Iterator It=pro.entryset (). iterator ();
while (It.hasnext ()) {
Map.entry entry= (Map.entry) it.next ();
Object key = Entry.getkey ();
Object value = Entry.getvalue ();
SYSTEM.OUT.PRINTLN (key + ":" +value);
}
Suppose the content in Wahaha.properties is:
------------------------------
Name1=xxxx
Name2=yyyyy
Name3=zzzzzzz
------------------------------
The above code will output:
--------------------------
Name1
Name2
Name3
Xxxx
Yyyyy
Zzzzzzz
Name1:xxxx
Name2:yyyyy
Name3:zzzzzzz
---------------------------------