應用程式與Applet不同,沒有自動安裝的安全管理器。預設情況下,應用程式具備完全的許可權。這裡建立一個應用程式獲得系統屬性值
/*
* @(#)GetSysprop.java 1.0 06/08/07
* get the system properties
* jiazhen 2006.08.07
*/
import java.security.*;
class getSysProp
{
public static void main(String args[]){
String s;
try{
//預設返回字串為not specified
//獲得系統名稱
s=System.getProperty("os.name","not specified");
System.out.println("The name of your operating system is:"+s);
//獲得Java虛擬機器版本號碼
s=System.getProperty("java.version","not specified");
System.out.println("Your user home directory is:"+s);
//獲得使用者路徑
s=System.getProperty("usr.home","not specified");
System.out.println("Your user home directory is:"+s);
//獲得java_home
s=System.getProperty("java.home","not specified");
System.out.println("Your JRE installation directory is:"+s);
}
catch(Exception e){
e.printStackTrace();
}
}
}
java 策略檔案並沒有對所有的系統屬性授權,當程式讀取沒有被授權的系統屬性時,便會拋出異常。要獲得某些系統屬性的存取權限,可以自己建立策略檔案。