• 通过java的Runtime.getRuntime()和System.getProperties()来获取系统的信息


    第一种,通过Runtime.getRuntime()来获取系统信息。

    通过java来获取系统以下的信息:

    主机名:          

    OS 名称:         
    OS 版本:         

    OS 制造商:      

    OS 配置:         

    独立工作站
    OS 构件类型:     

    注册的所有人:    

    注册的组织:      

    产品 ID:       
    初始安装日期:    

    系统启动时间:    

    系统制造商:      
    系统型号:        

    系统类型:        

    处理器:           
    BIOS 版本:       

    Windows 目录:    

    系统目录:       

    启动设备:     

    系统区域设置:    

    输入法区域设置:  
    时区:            

    物理内存总量:   

    可用的物理内存:  虚拟内存:

    最大值: 虚拟内存:

    可用:  虚拟内存:

    使用中: 4,442 MB
    页面文件位置:  

     域:          

     登录服务器:  

    修补程序:                        
    网卡:      

     1 import java.io.IOException;
     2 public class testCase {
     3 
     4     public static void main(String[] args) {
     5         
     6         /**
     7          * cmd空格/k空格systeminfo:执行字符串指定的命令但保留
     8          * 
     9          * systeminfo:查看系统信息
    10          */
    11         try {
    12             Runtime.getRuntime().exec("cmd /k systeminfo > d:/xx.txt");
    13             System.out.println("执行完毕!");
    14         } catch (IOException e) {
    15             System.out.println("生成文件失败!");
    16             e.printStackTrace();
    17         }
    18     }
    19 }


    到D盘查看一下xx.txt文件。

    可以看见:

     第二种,通过Properties props=System.getProperties();来获取系统信息。

    package com.souvc.test;
    
    import java.util.Enumeration;
    import java.util.Iterator;
    import java.util.Properties;
    import java.util.Map.Entry;
    
    public class SystemInfo {
    
        public static void main(String[] args) {
    
           Properties props=System.getProperties(); 
           
           // show keys  
           //showKeys(props);  
     
           // show values  
           //showValues(props);  
     
           // show keys and values  
           showKeysAndValues(props);
           
           //show SystemInfo
           showSystemInfo(props);
           
        }
    
        /**
         * 
         *显示Keys-values值
         */
        private static void showKeysAndValues(Properties props) {
            Iterator<Entry<Object, Object>> it = props.entrySet().iterator();  
            while (it.hasNext()) {  
                Entry<Object, Object> entry = it.next();  
                Object key = entry.getKey();  
                Object value = entry.getValue();  
                System.out.println("key   :" + key);  
                System.out.println("value :" + value);  
                System.out.println("------------------------");  
            }  
            
        }
    
        /**
         * 
         *显示values值
         */
        private static void showValues(Properties props) {
            Enumeration<Object> enu = props.elements();  
            while (enu.hasMoreElements()) {  
                Object value = enu.nextElement();  
                System.out.println(value);  
            }  
            
        }
    
        /**
         * 
         *显示Keys值
         */
        private static void showKeys(Properties props) {
            Enumeration<?> enu = props.propertyNames();  
            while (enu.hasMoreElements()) {  
                Object key = enu.nextElement();  
                System.out.println(key);  
            }  
        }
        
        /**
         * 
         *显示具体意义的值
         */
        
        private static void showSystemInfo(Properties props) {
           System.out.println("Java的运行环境版本:"+props.getProperty("java.version"));
           System.out.println("Java的运行环境供应商:"+props.getProperty("java.vendor"));
           System.out.println("Java供应商的URL:"+props.getProperty("java.vendor.url"));
           System.out.println("Java的安装路径:"+props.getProperty("java.home"));
           System.out.println("Java的虚拟机规范版本:"+props.getProperty("java.vm.specification.version"));
           System.out.println("Java的虚拟机规范供应商:"+props.getProperty("java.vm.specification.vendor"));
           System.out.println("Java的虚拟机规范名称:"+props.getProperty("java.vm.specification.name"));
           System.out.println("Java的虚拟机实现版本:"+props.getProperty("java.vm.version"));
           System.out.println("Java的虚拟机实现供应商:"+props.getProperty("java.vm.vendor"));
           System.out.println("Java的虚拟机实现名称:"+props.getProperty("java.vm.name"));
           System.out.println("Java运行时环境规范版本:"+props.getProperty("java.specification.version"));
           System.out.println("Java运行时环境规范供应商:"+props.getProperty("java.specification.vender"));
           System.out.println("Java运行时环境规范名称:"+props.getProperty("java.specification.name"));
           System.out.println("Java的类格式版本号:"+props.getProperty("java.class.version"));
           System.out.println("Java的类路径:"+props.getProperty("java.class.path"));
           System.out.println("加载库时搜索的路径列表:"+props.getProperty("java.library.path"));
           System.out.println("默认的临时文件路径:"+props.getProperty("java.io.tmpdir"));
           System.out.println("一个或多个扩展目录的路径:"+props.getProperty("java.ext.dirs"));
           System.out.println("操作系统的名称:"+props.getProperty("os.name"));
           System.out.println("操作系统的构架:"+props.getProperty("os.arch"));
           System.out.println("操作系统的版本:"+props.getProperty("os.version"));
           System.out.println("文件分隔符:"+props.getProperty("file.separator"));   //在 unix 系统中是"/"
           System.out.println("路径分隔符:"+props.getProperty("path.separator"));   //在 unix 系统中是":"
           System.out.println("行分隔符:"+props.getProperty("line.separator"));   //在 unix 系统中是"/n"
           System.out.println("用户的账户名称:"+props.getProperty("user.name"));
           System.out.println("用户的主目录:"+props.getProperty("user.home"));
           System.out.println("用户的当前工作目录:"+props.getProperty("user.dir"));
        }
    
    }

    效果如下:

    key   :java.runtime.name
    value :Java(TM) SE Runtime Environment
    ------------------------
    key   :sun.boot.library.path
    value :D:Javajdk1.6.0_43jrein
    ------------------------
    key   :java.vm.version
    value :20.14-b01
    ------------------------
    key   :java.vm.vendor
    value :Sun Microsystems Inc.
    ------------------------
    key   :java.vendor.url
    value :http://java.sun.com/
    ------------------------
    key   :path.separator
    value :;
    ------------------------
    key   :java.vm.name
    value :Java HotSpot(TM) 64-Bit Server VM
    ------------------------
    key   :file.encoding.pkg
    value :sun.io
    ------------------------
    key   :sun.java.launcher
    value :SUN_STANDARD
    ------------------------
    key   :user.country
    value :CN
    ------------------------
    key   :sun.os.patch.level
    value :Service Pack 1
    ------------------------
    key   :java.vm.specification.name
    value :Java Virtual Machine Specification
    ------------------------
    key   :user.dir
    value :E:souvcXTXL
    ------------------------
    key   :java.runtime.version
    value :1.6.0_43-b01
    ------------------------
    key   :java.awt.graphicsenv
    value :sun.awt.Win32GraphicsEnvironment
    ------------------------
    key   :java.endorsed.dirs
    value :D:Javajdk1.6.0_43jrelibendorsed
    ------------------------
    key   :os.arch
    value :amd64
    ------------------------
    key   :java.io.tmpdir
    value :C:UsersADMINI~1AppDataLocalTemp
    ------------------------
    key   :line.separator
    value :
    
    ------------------------
    key   :java.vm.specification.vendor
    value :Sun Microsystems Inc.
    ------------------------
    key   :user.variant
    value :
    ------------------------
    key   :os.name
    value :Windows 7
    ------------------------
    key   :sun.jnu.encoding
    value :GBK
    ------------------------
    key   :java.library.path
    value :D:Javajdk1.6.0_43in;C:WindowsSunJavain;C:Windowssystem32;C:Windows;D:/Program Files (x86)/eclipse/jre/bin/client;D:/Program Files (x86)/eclipse/jre/bin;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:Javajdk1.6.0_43in;D:Javajdk1.6.0_43jrein;C:Program Files (x86)MySQLMySQL Server 5.1in;D:Program FilesTortoiseSVNin;.
    ------------------------
    key   :java.specification.name
    value :Java Platform API Specification
    ------------------------
    key   :java.class.version
    value :50.0
    ------------------------
    key   :sun.management.compiler
    value :HotSpot 64-Bit Tiered Compilers
    ------------------------
    key   :os.version
    value :6.1
    ------------------------
    key   :user.home
    value :C:UsersAdministrator
    ------------------------
    key   :user.timezone
    value :
    ------------------------
    key   :java.awt.printerjob
    value :sun.awt.windows.WPrinterJob
    ------------------------
    key   :file.encoding
    value :UTF-8
    ------------------------
    key   :java.specification.version
    value :1.6
    ------------------------
    key   :java.class.path
    value :E:souvcXTXLuildclasses;D:apache-tomcat-6.0.43libannotations-api.jar;D:apache-tomcat-6.0.43libcatalina-ant.jar;D:apache-tomcat-6.0.43libcatalina-ha.jar;D:apache-tomcat-6.0.43libcatalina-tribes.jar;D:apache-tomcat-6.0.43libcatalina.jar;D:apache-tomcat-6.0.43libecj-4.3.1.jar;D:apache-tomcat-6.0.43libel-api.jar;D:apache-tomcat-6.0.43libjasper-el.jar;D:apache-tomcat-6.0.43libjasper.jar;D:apache-tomcat-6.0.43libjsp-api.jar;D:apache-tomcat-6.0.43libservlet-api.jar;D:apache-tomcat-6.0.43lib	omcat-coyote.jar;D:apache-tomcat-6.0.43lib	omcat-dbcp.jar;D:apache-tomcat-6.0.43lib	omcat-i18n-es.jar;D:apache-tomcat-6.0.43lib	omcat-i18n-fr.jar;D:apache-tomcat-6.0.43lib	omcat-i18n-ja.jar;E:souvcXTXLWebRootWEB-INFlibantlr-2.7.6.jar;E:souvcXTXLWebRootWEB-INFlibaopalliance.jar;E:souvcXTXLWebRootWEB-INFlibasm-attrs.jar;E:souvcXTXLWebRootWEB-INFlibasm.jar;E:souvcXTXLWebRootWEB-INFlibaspectjweaver.jar;E:souvcXTXLWebRootWEB-INFlibc3p0-0.9.1.jar;E:souvcXTXLWebRootWEB-INFlibcglib-2.1.3.jar;E:souvcXTXLWebRootWEB-INFlibcommons-collections-2.1.1.jar;E:souvcXTXLWebRootWEB-INFlibcommons-collections-3.1.jar;E:souvcXTXLWebRootWEB-INFlibcommons-dbcp-1.2.2.jar;E:souvcXTXLWebRootWEB-INFlibcommons-logging-1.0.4.jar;E:souvcXTXLWebRootWEB-INFlibcommons-logging.jar;E:souvcXTXLWebRootWEB-INFlibcommons-pool.jar;E:souvcXTXLWebRootWEB-INFlibdom4j-1.6.1.jar;E:souvcXTXLWebRootWEB-INFlibfreemarker.jar;E:souvcXTXLWebRootWEB-INFlibhibernate-tools.jar;E:souvcXTXLWebRootWEB-INFlibhibernate3.jar;E:souvcXTXLWebRootWEB-INFlibjackson-annotations-2.4.1.jar;E:souvcXTXLWebRootWEB-INFlibjackson-core-2.4.1.jar;E:souvcXTXLWebRootWEB-INFlibjackson-databind-2.4.1.jar;E:souvcXTXLWebRootWEB-INFlibjstl.jar;E:souvcXTXLWebRootWEB-INFlibjta.jar;E:souvcXTXLWebRootWEB-INFlibjunit-4.4.jar;E:souvcXTXLWebRootWEB-INFliblog4j-1.2.11.jar;E:souvcXTXLWebRootWEB-INFlibmysql-connector-java-5.1.6-bin.jar;E:souvcXTXLWebRootWEB-INFlibojdbc6.jar;E:souvcXTXLWebRootWEB-INFlibspring-aop-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-aspects-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-beans-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-context-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-core-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-expression-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-jdbc-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-orm-3.2.7.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-tx-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-web-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-webmvc-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibstandard.jar
    ------------------------
    key   :user.name
    value :Administrator
    ------------------------
    key   :java.vm.specification.version
    value :1.0
    ------------------------
    key   :sun.java.command
    value :com.souvc.test.SystemInfo
    ------------------------
    key   :java.home
    value :D:Javajdk1.6.0_43jre
    ------------------------
    key   :sun.arch.data.model
    value :64
    ------------------------
    key   :user.language
    value :zh
    ------------------------
    key   :java.specification.vendor
    value :Sun Microsystems Inc.
    ------------------------
    key   :awt.toolkit
    value :sun.awt.windows.WToolkit
    ------------------------
    key   :java.vm.info
    value :mixed mode
    ------------------------
    key   :java.version
    value :1.6.0_43
    ------------------------
    key   :java.ext.dirs
    value :D:Javajdk1.6.0_43jrelibext;C:WindowsSunJavalibext
    ------------------------
    key   :sun.boot.class.path
    value :D:Javajdk1.6.0_43jrelib
    esources.jar;D:Javajdk1.6.0_43jrelib
    t.jar;D:Javajdk1.6.0_43jrelibsunrsasign.jar;D:Javajdk1.6.0_43jrelibjsse.jar;D:Javajdk1.6.0_43jrelibjce.jar;D:Javajdk1.6.0_43jrelibcharsets.jar;D:Javajdk1.6.0_43jrelibmodulesjdk.boot.jar;D:Javajdk1.6.0_43jreclasses
    ------------------------
    key   :java.vendor
    value :Sun Microsystems Inc.
    ------------------------
    key   :file.separator
    value :
    ------------------------
    key   :java.vendor.url.bug
    value :http://java.sun.com/cgi-bin/bugreport.cgi
    ------------------------
    key   :sun.io.unicode.encoding
    value :UnicodeLittle
    ------------------------
    key   :sun.cpu.endian
    value :little
    ------------------------
    key   :sun.desktop
    value :windows
    ------------------------
    key   :sun.cpu.isalist
    value :amd64
    ------------------------
    Java的运行环境版本:1.6.0_43
    Java的运行环境供应商:Sun Microsystems Inc.
    Java供应商的URL:http://java.sun.com/
    Java的安装路径:D:Javajdk1.6.0_43jre
    Java的虚拟机规范版本:1.0
    Java的虚拟机规范供应商:Sun Microsystems Inc.
    Java的虚拟机规范名称:Java Virtual Machine Specification
    Java的虚拟机实现版本:20.14-b01
    Java的虚拟机实现供应商:Sun Microsystems Inc.
    Java的虚拟机实现名称:Java HotSpot(TM) 64-Bit Server VM
    Java运行时环境规范版本:1.6
    Java运行时环境规范供应商:null
    Java运行时环境规范名称:Java Platform API Specification
    Java的类格式版本号:50.0
    Java的类路径:E:souvcXTXLuildclasses;D:apache-tomcat-6.0.43libannotations-api.jar;D:apache-tomcat-6.0.43libcatalina-ant.jar;D:apache-tomcat-6.0.43libcatalina-ha.jar;D:apache-tomcat-6.0.43libcatalina-tribes.jar;D:apache-tomcat-6.0.43libcatalina.jar;D:apache-tomcat-6.0.43libecj-4.3.1.jar;D:apache-tomcat-6.0.43libel-api.jar;D:apache-tomcat-6.0.43libjasper-el.jar;D:apache-tomcat-6.0.43libjasper.jar;D:apache-tomcat-6.0.43libjsp-api.jar;D:apache-tomcat-6.0.43libservlet-api.jar;D:apache-tomcat-6.0.43lib	omcat-coyote.jar;D:apache-tomcat-6.0.43lib	omcat-dbcp.jar;D:apache-tomcat-6.0.43lib	omcat-i18n-es.jar;D:apache-tomcat-6.0.43lib	omcat-i18n-fr.jar;D:apache-tomcat-6.0.43lib	omcat-i18n-ja.jar;E:souvcXTXLWebRootWEB-INFlibantlr-2.7.6.jar;E:souvcXTXLWebRootWEB-INFlibaopalliance.jar;E:souvcXTXLWebRootWEB-INFlibasm-attrs.jar;E:souvcXTXLWebRootWEB-INFlibasm.jar;E:souvcXTXLWebRootWEB-INFlibaspectjweaver.jar;E:souvcXTXLWebRootWEB-INFlibc3p0-0.9.1.jar;E:souvcXTXLWebRootWEB-INFlibcglib-2.1.3.jar;E:souvcXTXLWebRootWEB-INFlibcommons-collections-2.1.1.jar;E:souvcXTXLWebRootWEB-INFlibcommons-collections-3.1.jar;E:souvcXTXLWebRootWEB-INFlibcommons-dbcp-1.2.2.jar;E:souvcXTXLWebRootWEB-INFlibcommons-logging-1.0.4.jar;E:souvcXTXLWebRootWEB-INFlibcommons-logging.jar;E:souvcXTXLWebRootWEB-INFlibcommons-pool.jar;E:souvcXTXLWebRootWEB-INFlibdom4j-1.6.1.jar;E:souvcXTXLWebRootWEB-INFlibfreemarker.jar;E:souvcXTXLWebRootWEB-INFlibhibernate-tools.jar;E:souvcXTXLWebRootWEB-INFlibhibernate3.jar;E:souvcXTXLWebRootWEB-INFlibjackson-annotations-2.4.1.jar;E:souvcXTXLWebRootWEB-INFlibjackson-core-2.4.1.jar;E:souvcXTXLWebRootWEB-INFlibjackson-databind-2.4.1.jar;E:souvcXTXLWebRootWEB-INFlibjstl.jar;E:souvcXTXLWebRootWEB-INFlibjta.jar;E:souvcXTXLWebRootWEB-INFlibjunit-4.4.jar;E:souvcXTXLWebRootWEB-INFliblog4j-1.2.11.jar;E:souvcXTXLWebRootWEB-INFlibmysql-connector-java-5.1.6-bin.jar;E:souvcXTXLWebRootWEB-INFlibojdbc6.jar;E:souvcXTXLWebRootWEB-INFlibspring-aop-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-aspects-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-beans-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-context-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-core-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-expression-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-jdbc-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-orm-3.2.7.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-tx-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-web-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibspring-webmvc-3.2.8.RELEASE.jar;E:souvcXTXLWebRootWEB-INFlibstandard.jar
    加载库时搜索的路径列表:D:Javajdk1.6.0_43in;C:WindowsSunJavain;C:Windowssystem32;C:Windows;D:/Program Files (x86)/eclipse/jre/bin/client;D:/Program Files (x86)/eclipse/jre/bin;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:Javajdk1.6.0_43in;D:Javajdk1.6.0_43jrein;C:Program Files (x86)MySQLMySQL Server 5.1in;D:Program FilesTortoiseSVNin;.
    默认的临时文件路径:C:UsersADMINI~1AppDataLocalTemp
    一个或多个扩展目录的路径:D:Javajdk1.6.0_43jrelibext;C:WindowsSunJavalibext
    操作系统的名称:Windows 7
    操作系统的构架:amd64
    操作系统的版本:6.1
    文件分隔符:
    路径分隔符:;
    行分隔符:
    
    用户的账户名称:Administrator
    用户的主目录:C:UsersAdministrator
    用户的当前工作目录:E:souvcXTXL
    View Code

    原文作者:daliu_it
    博文出处:http://www.cnblogs.com/liuhongfeng/p/4184805.html

    本文版权归作者和博客园共有,但未经作者同意转载必须保留以上的声明且在放在文章页面明显位置。谢谢合作。

  • 相关阅读:
    mac鼠标滚动方向自然问题
    Android学习笔记(9):使用XML文件和Java代码控制UI界面
    新版Eclipse找不到Java EE Module Dependencies选项
    JAR包放在WEB-INF/lib子目录报ClassNotFoundException解决方案
    Eclipse中將Java项目转变为Java Web项目
    java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceE解决方法
    MyBatis数据持久化(九)动态sql
    MyBatis数据持久化(八)sql复用
    MyBatis数据持久化(七)多表连接查询
    JQuery实现的弹窗效果
  • 原文地址:https://www.cnblogs.com/liuhongfeng/p/4184805.html
Copyright © 2020-2023  润新知