Java获得系统环境变量
2010-09-06 15:31
351 查看
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[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
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[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
相关文章推荐
- Java获得系统环境变量
- Java获得系统环境变量
- Java获得系统环境变量
- Java获得系统环境变量
- Java进程系统环境变量说明
- [Java] JDK 系统环境变量设置 bat
- Java mac系统下JDK安装和环境变量的配置
- Linux系统下配置Java环境变量,配置Tomcat服务器、mongodb数据库
- 获得操作系统路径(java系统变量相关)
- Java的System.getProperty()方法可以获取系统变量和System.getenv()获取系统环境变量
- bat批处理设置Java JDK系统环境变量文件
- java 获取系统变量(环境变量和设置变量)
- java如系统环境变量和bat设环境变量
- vc 获得和设置系统环境变量
- java中获取系统属性以及环境变量
- bat批处理设置Java JDK系统环境变量文件
- Java CMD 命令设置系统环境变量(windows)
- 用java实现修改系统的环境变量并使其不需重启就生效
- java 读取系统环境变量和值
- java 读取系统属性及环境变量