當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java System setProperties()用法及代碼示例

Java System 類的 setProperties() 方法將係統的屬性設置為屬性的參數。

用法:

public static void setProperties(Properties props)

參數:

props- 這是新的係統屬性。

拋出:

SecurityException:如果安全管理器存在且其 checkPropertiesAccess 方法不允許訪問係統屬性,則會拋出此異常。

示例

import java.io.FileNotFoundException;
import java.util.Properties;

public class SystemSetPropertiesExample {

    public static void main(String[] args) throws FileNotFoundException {
        System.out.println("Before setProperties method = "+System.getProperty("user.dir"));
        Properties p= System.getProperties();
        p.put("user.dir", "this/is/the/new/user/dir/path");
        System.setProperties(p);
        System.out.println("After setProperties method = "+System.getProperty("user.dir"));

    }
}

輸出:

Before setProperties method = C:\Users\Shubham Jadon\eclipse-workspace\tpoint
After setProperties method = this/is/the/new/user/dir/path






相關用法


注:本文由純淨天空篩選整理自 Java System setProperties() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。