目录

static String getProperty(String key)

描述 (Description)

java.lang.System.getProperty(String key)方法获取指定key指示的系统属性。

声明 (Declaration)

以下是java.lang.System.getProperty()方法的声明

public static String getProperty(String key)

参数 (Parameters)

key - 这是系统属性的名称。

返回值 (Return Value)

此方法返回系统属性的字符串值,如果没有具有该键的属性,则返回null。

异常 (Exception)

  • SecurityException - 如果存在安全管理器且其checkPropertyAccess方法不允许访问指定的系统属性。

  • NullPointerException - 如果key为null。

  • IllegalArgumentException - 如果key为空。

例子 (Example)

以下示例显示了java.lang.System.getProperty()方法的用法。

package com.iowiki;
import java.lang.*;
public class SystemDemo {
   public static void main(String[] args) {
      // prints the name of the system property
      System.out.println(System.getProperty("user.dir"));
      // prints the name of the Operating System
      System.out.println(System.getProperty("os.name"));
      // prints Java Runtime Version
      System.out.println(System.getProperty("java.runtime.version" ));
   }
} 

让我们编译并运行上面的程序,这将产生以下结果 -

C:\Program Files\Java\jdk1.6.0_06\bin
Windows XP
1.6.0_06-b02
↑回到顶部↑
WIKI教程 @2018