Questo nice article ci mostra come stampare tutte le proprietà correnti del sistema su STDOUT, ma ho bisogno di convertire tutto ciò che è in System.getProperties()
in un HashMap<String,String>
.Come convertire tutte le proprietà di sistema Java in HashMap <String, String>?
Quindi se v'è una proprietà di sistema chiamato "baconator", con un valore di "sì!", Che ho impostato con System.setProperty("baconator, "yes!")
, allora voglio il HashMap
di avere una chiave di baconator
e un rispettivo valore di yes!
, ecc Stessa idea per le proprietà di sistema all.
ho provato questo:
Properties systemProperties = System.getProperties();
for(String propertyName : systemProperties.keySet())
;
Ma poi ottiene un errore:
Type mismatch: cannot convert from element type Object to String
Allora ho provato:
Properties systemProperties = System.getProperties();
for(String propertyName : (String)systemProperties.keySet())
;
e sto ottenendo questo errore:
Can only iterate over an array or an instance of java.lang.Iterable
Qualche idea?
Questo è un duplicato di http://stackoverflow.com/questions/17209260/converting-java-util-properties-to-hashmapstring-string –