Java获得系统环境变

http://35java.com/zhibo/forum.php?mod=viewthread&tid=356&extra=page%3D4
package org.loon.test;

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

/** *//**
* <p>
* Title: LoonFramework
* </p>
* <p>
* Description:
* </p>
* <p>
* Copyright: Copyright (c) 2007
* </p>
* <p>
* Company: LoonFramework
* </p>
*
* @author chenpeng
* @email:ceponline@yahoo.com.cn
* @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 <K>
* @param <V>
*/
@SuppressWarnings("unchecked")
public
static
<K, V>
void systemProperties() ...{
Properties p = System.getProperties();
TreeMap<K, V> map =
new TreeMap<K, V>();
map.putAll((Map<?
extends K, ?
extends V>) 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 = System.getProperty(as);
System.out.println((as +
"="
+ ((i==4)?envStr+"
"+isSun(envStr):envStr)).intern());
}
catch (Exception ex) ...{
}
}

}

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

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值