Java中System.setProperty()用法
轉(zhuǎn)載自?https://www.cnblogs.com/chasewade/p/3387390.html
/*
?* 設(shè)置指定鍵對(duì)值的系統(tǒng)屬性
?* setProperty (String prop, String value);
?*?
?* 參數(shù):
?* prop - 系統(tǒng)屬性的名稱。
?* value - 系統(tǒng)屬性的值。??
?*?
?* 返回:
?* 系統(tǒng)屬性以前的值,如果沒(méi)有以前的值,則返回 null。
?*?
?* 拋出:??
?* SecurityException - 如果安全管理器存在并且其 checkPermission 方法不允許設(shè)置指定屬性。
?* NullPointerException - 如果 key 或 value 為 null。
?* IllegalArgumentException - 如果 key 為空。
?* 注:這里的system,系統(tǒng)指的是 JRE (runtime)system,不是指 OS。
?*?
*/
//實(shí)例
System.setProperty("Property1", "abc");
System.setProperty("Property2","def");
//這樣就把第一個(gè)參數(shù)設(shè)置成為系統(tǒng)的全局變量!可以在項(xiàng)目的任何一個(gè)地方 通過(guò)System.getProperty("變量");來(lái)獲得,
//System.setProperty 相當(dāng)于一個(gè)靜態(tài)變量? ,存在內(nèi)存里面!
public class SystemTest {static {setValue();}public static void setValue() {System.setProperty("name", "張三");System.setProperty("age", "28");}public static void main(String[] args) {System.out.println(System.getProperty("name"));System.out.println(System.getProperty("age"));} }?輸出:
總結(jié)
以上是生活随笔為你收集整理的Java中System.setProperty()用法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Intellij IDEA中安装使用Pl
- 下一篇: Java8中使用以下类计算日期时间差:P