public class Test {
public Test() {
Runtime ObjRunTime = Runtime.getRuntime();
byte[] env = new byte[1000];
try{
Process ObjPrcess = ObjRunTime.exec("cmd /c echo %Path%");
InputStream in = ObjPrcess.getInputStream();
in.read(env);
}catch(Exception e) { e.printStackTrace();}
System.out.println(new String(env).trim());
}
public static void main(String[] args) {
Test test = new Test();
}
}
首先,java.lang.Runtime执行WINDOWS命令.要说明"echo"并不是系统命令所以要在WIN SHELL内执行.
其次,java.lang.Process取得执行结果.
再次,转化为字符串返回.
谢谢诸君关注,来者有分.稍后结贴!
Class System的Doc
getProperties
public static Properties getProperties()Determines the current system properties.
First, if there is a security manager, its checkPropertiesAccess method is called with no arguments. This may result in a security exception.
The current set of system properties for use by the getProperty(String) method is returned as a Properties object. If there is no current set of system properties, a set of system properties is first created and initialized. This set of system properties always includes values for the following keys:
Key Description of Associated Value
java.io.tmpdir Default temp file path
os.name Operating system name
os.arch Operating system architecture
os.version Operating system version
等等