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 the enumeration of all keys in the attribute list
Enumeration enu2 = pro. propertynames ();
While (enu2.hasmoreelements ()){
String key = (string) enu2.nextelement ();
System. Out. println (key );
}
// Properties is inherited from hashtable. Elements () is a hashtable method that returns the enumerated values in the hash table.
Enumeration enu = pro. Elements ();
While (enu. hasmoreelements ()){
String key = (string) enu. nextelement ();
System. Out. println (key );
}
// Properties inherits from hashtable. entryset () is the hashtable method,
// Return 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 );
}
Assume that 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