Java System.setProperty()用法詳解
/** 設(shè)置指定鍵對(duì)值的系統(tǒng)屬性* setProperty (String prop, String value);* * 參數(shù):* prop - 系統(tǒng)屬性的名稱。* value - 系統(tǒng)屬性的值。 * * 返回:* 系統(tǒng)屬性以前的值,如果沒有以前的值,則返回 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è)地方 通過System.getProperty('變量');來獲得,
//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')); }}
輸出
張三
28
到此這篇關(guān)于Java System.setProperty()用法詳解的文章就介紹到這了,更多相關(guān)Java System.setProperty()內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. arcgis js完整懸停效果實(shí)現(xiàn)demo2. .Net中Task Parallel Library的基本用法3. JavaScript實(shí)現(xiàn)form提交,回車提交URL地址偽靜態(tài) 原創(chuàng)4. Android 通過cmake的方式接入opencv的方法步驟5. ASP.NET Core自定義中間件的方式詳解6. 《CSS3實(shí)戰(zhàn)》筆記--漸變?cè)O(shè)計(jì)(二)7. css代碼優(yōu)化的12個(gè)技巧8. ASP.NET MVC使用typeahead.js實(shí)現(xiàn)輸入智能提示功能9. 使用IDEA編寫jsp時(shí)EL表達(dá)式不起作用的問題及解決方法10. jsp實(shí)現(xiàn)登錄界面
