设置Java系统属性,为什么';这个代码不起作用吗?
下面的代码似乎不起作用,但我相信它曾经起作用设置Java系统属性,为什么';这个代码不起作用吗?,java,properties,system,Java,Properties,System,下面的代码似乎不起作用,但我相信它曾经起作用 public static void main(String args[]) { Properties currentProperties = System.getProperties(); Properties p = new Properties(currentProperties); System.setProperties(p); } 在构造新属性对象的过程中,不会添加旧属性,因此当调用System.setPrope
public static void main(String args[])
{
Properties currentProperties = System.getProperties();
Properties p = new Properties(currentProperties);
System.setProperties(p);
}
在构造新属性对象的过程中,不会添加旧属性,因此当调用System.setProperties时,它具有擦除所有系统属性的效果
同样奇怪的是,Oracle网站上有一个类似的代码示例
有人能解释一下为什么这个代码不起作用吗?我们应该做什么来代替这个代码呢
我使用的是Java 1.7_75 64-0位
谢谢
丰富的
就我而言,这是创建和保存属性的唯一方法 看一看。建设者
public Properties(Properties defaults)
如上所述
创建具有指定默认值的空属性列表
创建一个新的属性实例,但不使用输入参数中的属性对其进行初始化,它只为这个新实例设置默认值。什么不起作用?你的代码最终什么都不做。你可以把import语句也包括进去吗?如果你想擦除,它不应该是
Properties p=newproperties()代码>?这并不能回答问题。您建议改进什么=我正在尝试给他通常用于属性文件的代码,这样他可能会看到错误。我不确定他想要实现什么,所以这是我能做的最好的了。你的代码很好,但是你是从一个文件读写的,而OP使用的是系统属性。
public Properties(Properties defaults)