System.setProperty();
-- 源码记录
/**
* Sets the system property indicated by the specified key.
* <p>
* First, if a security manager exists, its
* <code>SecurityManager.checkPermission</code> method
* is called with a <code>PropertyPermission(key, "write")</code>
* permission. This may result in a SecurityException being thrown.
* If no exception is thrown, the specified property is set to the given
* value.
* <p>
*
* @param key the name of the system property.
* @param value the value of the system property.
* @return the previous value of the system property,
* or <code>null</code> if it did not have one.
*
* @exception SecurityException if a security manager exists and its
* <code>checkPermission</code> method doesn't allow
* setting of the specified property.
* @exception NullPointerException if <code>key</code> or
* <code>value</code> is <code>null</code>.
* @exception IllegalArgumentException if <code>key</code> is empty.
* @see #getProperty
* @see java.lang.System#getProperty(java.lang.String)
* @see java.lang.System#getProperty(java.lang.String, java.lang.String)
* @see java.util.PropertyPermission
* @see SecurityManager#checkPermission
* @since 1.2
*/
简单翻译一下:
这就类似map,key - value 对,放于内存中,获取的时候就用getProperty(“key”),
然后还有各种的exception 异常,注意查看
然后再来一段代码,简单看一下
好多"张三" 的代码实例,看腻了…
换一个口味
public static void main(String[] args) {
//看一下,你的java运行时的版本
System.out.println("你的Java运行时的版本 ==>>"+System.getProperty("java.runtime.version" ));
//然后将你的java运行时版本修改,放心,只是展示变了
System.setProperty("java.runtime.version", "helloWorld");
//然后查看一下,修改之后的value
System.out.println("修改之后的java运行版本值 ==>>"+System.getProperty("java.runtime.version" ));
}