Java获得系统环境变量

package org.loon.test;

import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;

/** *//**
 *


 * Title: LoonFramework
 *


 *


 * Description:
 *


 *


 * Copyright: Copyright (c) 2007
 *


 *


 * Company: LoonFramework
 *


 *
 * @author chenpeng
 * @email:[email protected]
 * @version 0.1
 */
public class SystemInfo ...{

    public final static String envStr[] = ...{ "unknown OS type",
            "unknown OS version", "unknown OS architecture",
            "unknown JRE version", "unknown JRE vendor" };

    /** *//**
     * 遍历所有设置
     * @param
     * @param
     */
    @SuppressWarnings("unchecked")
    public static void systemProperties() ...{
        Properties p = System.getProperties();
        TreeMap map = new TreeMap();
        map.putAll((Map) p);
        Iterator itr = map.keySet().iterator();
        while (itr.hasNext()) ...{
            String key = (String) itr.next();
            String value = (String) map.get(key);
            System.out.println(key + "=" + value);
        }
    }

    /** *//**
     * sun制造标记
     * @param type
     * @return
     */
    public boolean isSun(String type) ...{
        return type.indexOf("Sun") != -1;
    }

    /** *//**
     * applet制造标记
     * @param type
     * @return
     */
    public boolean isApple(String type) ...{
        return type.indexOf("Apple") != -1;
    }

    /** *//**
     * hp制造标记
     * @param type
     * @return
     */
    public static boolean isHPUX(String type) ...{
        return type.indexOf("Hewlett-Packard Company") != -1;
    }

    /** *//**
     * ibm制造标记
     * @param type
     * @return
     */
    public static boolean isIBM(String type) ...{
        return type.indexOf("IBM") != -1;
    }

    /** *//**
     * Blackdown制造标记
     * @param type
     * @return
     */
    public static boolean isBlackdown(String type) ...{
        return type.indexOf("Blackdown") != -1;
    }

    /** *//**
     * bea制造标记
     * @param type
     * @return
     */
    public static boolean isBEAWithUnsafeSupport(String type) ...{
        if (type.indexOf("BEA") != -1) ...{
            String vmVersion = System.getProperty("java.vm.version");
            if (vmVersion.startsWith("R")) ...{
                return true;
            }
            String vmInfo = System.getProperty("java.vm.info");
            if (vmInfo != null) ...{
                return (vmInfo.startsWith("R25.1") || vmInfo
                        .startsWith("R25.2"));
            }
        }
        return false;
    }

   void getEnv() ...{
        // os.name 主机操作系统的名称
        // os.version 主机操作系统的版本
        // os.arch 主机操作系统的体系结构
        // java.version java版本
        // java.vendor java厂商
        String as[] = ...{ "os.name", "os.version", "os.arch", "java.version",
                "java.vendor" };
        for (int i = 0; i < as.length; i++) ...{
            try ...{
                envStr[i] = System.getProperty(as[i]);
                System.out.println((as[i] + "=" + ((i==4)?envStr[i]+" "+isSun(envStr[i]):envStr[i])).intern());
            } catch (Exception ex) ...{
            }
        }

    }

    public static void main(String[] args) ...{
        new SystemInfo().getEnv();
        System.out.println(" 全部设置 ");
        //显示所有设置
        systemProperties();
    }

}


转载:http://blog.csdn.net/cping1982/archive/2008/01/15/2045645.aspx

你可能感兴趣的:(10,JAVA,11,J2SE,java,string,制造,properties,iterator,exception)