美文网首页
System.getProperties 与 System.ge

System.getProperties 与 System.ge

作者: 喏喏2021 | 来源:发表于2021-11-17 10:39 被阅读0次

 一. System.getProperties() 使用

Properties props = System.getProperties();

System.out.println("props共有" + props.size() + "个属性");

int index = 0;

for(Iterator<Entry<Object, Object>> it = props.entrySet().iterator();it.hasNext();) {

    Entry<Object, Object> entry = it.next();

    System.out.println((++index) + ". " + entry);

}

二. System.getenv() 使用

index = 0;

Map m = System.getenv();

for(Iterator it = m.entrySet().iterator();it.hasNext();) {

    System.out.println((++index) + ". " + it.next());

}

三. 区别

1. System.getProperties() 是获取java系统的属性,主要是java虚拟机运行时的一些环境变量参数,可以通过java -DparamName=value来设置,

在eclipse中可以这样来设置

设置虚拟机变量参数

2. System.getenv() 是用来获取操作系统的环境变量,在eclipse中作如下配置

添加或编辑系统环境变量 可以读取操作系统中的变量

3. java虚拟机的参数系统可以在代码中维护,而操作系统的环境变量只能读取

手动设置虚拟机变量:System.setProperty("sun.cpu.isalist", System.getProperty("sun.cpu.isalist") + "abc");

相关文章

网友评论

      本文标题:System.getProperties 与 System.ge

      本文链接:https://www.haomeiwen.com/subject/jfkltrtx.html