- How do I read and write system properties using Java?
Read:
Properties props = System. getProperties ();
Enumeration prop_names = Props.propertynames ();
while (Prop_names.hasmoreelements ()) {
String prop_name = (string) prop_names.nextelement ();
String property = Props.getproperty (Prop_name);
System. out. println ("property" + Prop_name + "are" + Property + "'");
}
write:
system.setproperties (props);
- Briefly describe the structure and basic usage of the properties file
Structure: A file with the properties extension, the content is a mapping of key, value, for example "A=2″
Usage:
Public class Test {
Public static void main (String args[]) {
Try {
String name = "Test.properties";
InputStream in = new bufferedinputstream (new FileInputStream (name));
Properties P = new properties ();
P.load (in);
System. out. println ("A's value = =" + P.getproperty ("a"));
} Catch (Exception err) {
Err.printstacktrace ();
}
}
}
How do I read and write system properties using Java?