成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術(shù)文章
文章詳情頁

Java System.setProperty()用法詳解

瀏覽:36日期:2023-12-10 09:03:26

/** 設(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)!

標(biāo)簽: Java
相關(guān)文章: