天天看點

如何使用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 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();

最新内容請見作者的github頁:http://qaseven.github.io/