如何使用Java读写系统属性?

如何使用Java读写系统属性?
  读:
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 + “‘ is ‘”+ property + “‘”);
}
  写:
  System.setProperties(props);
   简述properties文件的结构和基本用法
  结构:扩展名为properties的文件,内容为key、value的映射,例如”a=2″
  用法:
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的值==” + p.getProperty(“a”));
} catch (Exception err) {
err.printStackTrace();
}
}
}
 

你可能感兴趣的:(java)