Get System Info

来源:互联网 发布:相片mv制作软件 编辑:程序博客网 时间:2024/05/01 03:13
Ch15     系统程序设计

1   System
1.1   I/O流
 public   static   InputStream   in:   读取字符的标准输入流。
 public   static   PrintStream   out:   标准输出流。
 public   static   PrintStream   err:   标准错误输出流。
1.2   系统属性
      (1)   属性
 java.version   版本号               java.vendor销售商  
 java.vendor.url                       java.home安装目录
 java.class.version类版本       java.class.path类路径
 os.name                                     os.arch支持的体系结构
 os.version                                 file.separator
 path.separator                         line.separator     行分隔符
 user.name                                 user.home         home目录
 user.dir   用户当前目录
      (2)   方法
 public   static   Properties   getProperties():   取系统属性。如果当前系统属性集不存在,则创建并初始化。
 public   static   void   setProperties(Properties   props)
 public   static   String   getProperty(String   key)
返回名为key的属性值。等效于System.getProperties().getProperty(key);
 public   static   String   getProperty(String   key,String   defaultValue)
返回名为key的属性值。若没定义则返回defaultValue。它等效于System.getProperties().getProperty(key,def);

(3)   属性值的解码       属性值转换成数值(对象)
 static   boolean   Boolean.getBoolean(String   name)
name为”true”(不区分大小写)时,   返回true,否则false
 static   Integer   Integer.getInteger(String   name)
如果没有数字形式,返回null。
 static   Integer   Integer.getInteger(String   name,Integer   def):   如果没有数字形式,返回缺省值def
 static   Long   Long.getLong(String   nm)
 static   Long   Long.getLong(String   nm,Long   def)
      (4)   Eample
public   static   File   personal(String   fileName){
  String   home   =   System.getProperty( "user.home ");
  if     (home   ==   null)       return   null;
  else   return   new   File(home,fileName);
}


            StringBuffer   props   =   new   StringBuffer();
            props.append( "\nOS   Name:   ");
            props.append(System.getProperty( "os.name "));
            props.append( "\nOS   Version:   ");
            props.append(System.getProperty( "os.version "));
            props.append( "\nOS   Architecture:   ");
            props.append(System.getProperty( "os.arch "));
            props.append( "\nJVM   Version:   ");
            props.append(System.getProperty( "java.runtime.version "));
            props.append( "\nJVM   Vendor:   ");
            props.append(System.getProperty( "java.vm.vendor "));
            System.out.println(props.toString());

原创粉丝点击