星期二, 二月 10, 2004

java get system environment variable

/**
* 得到java VM预先定义的系统变量
* jdk verison 1.4.2
*/
public class listallproperties
{
Properties ttl= System.getProperties();
Enumeration te = ttl.propertyNames();
while(te.hasMoreElements())
{
String objectname=te.nextElement();
System.out.println(objectname +" = "+System.getProperty((objectname)));
}
}

/**BeanShell 版本
*修改System.out.println为print方法.
*/
import java.util.*;
Properties ttl= System.getProperties();
Enumeration te = ttl.propertyNames();
while(te.hasMoreElements())
{
String objectname=te.nextElement();
print(objectname +" = "+System.getProperty((objectname)));
}