public static String setProperty(String key, String value) Sets the system property indicated by the specified key. First, if a security manager exists, its SecurityManager.checkPermission method is called with a PropertyPermission(key, "write") permission. This may result in a SecurityException being thrown. If no exception is thrown, the specified property is set to the given value. Parameters: key - the name of the system property. value - the value of the system property. Returns: the previous value of the system property, or null if it did not have one.
p.setProperty("test", "true");
System.out.println("Boolean.getBoolean():" + Boolean.getBoolean("test"));
static boolean getBoolean(String name)
Returns true if and only if the system property named by the argument exists and is equal to the string "true".
p.setProperty("test", "true");
System.out.println("Boolean.getBoolean():" + Boolean.getBoolean("test"));提问:
setProperty()中设置的"test"和"true",都是什么意思?
setProperty()中设置的"test"和"true",都是什么意思?-----------------
设置 [名 - 值] 的对应关系,像Hashtable中的put(Object key, Object value)
String value)
Sets the system property indicated by the specified key.
First, if a security manager exists, its SecurityManager.checkPermission method is called with a PropertyPermission(key, "write") permission. This may result in a SecurityException being thrown. If no exception is thrown, the specified property is set to the given value.
Parameters:
key - the name of the system property.
value - the value of the system property.
Returns:
the previous value of the system property, or null if it did not have one.
首先,如果有一安全管理器,调用验证方法SecurityManager.checkPermission(key, "write"),可能会可出一个安全异常。
如果没有抛出异常,用value设置指定的系统属性值。
返回以前的值或null。
p.setProperty("test", "true");
System.out.println("Boolean.getBoolean():" + Boolean.getBoolean(p.getProperty("test").tostring));