Java 应用程序默认权限(简例)

来源:互联网 发布:上海专业seo公司 编辑:程序博客网 时间:2024/06/06 23:51

应用程序与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 策略文件并没有对所有的系统属性授权,当程序读取没有被授权的系统属性时,便会抛出异常。要获得某些系统属性的访问权限,可以自己建立策略文件。