php 获取系统环境变量,java读取操作系统环境变量
java讀取操作系統環境變量import java.util.*;
import java.io.*;
class SysProb
{
//返回當前系統變量的函數,結果放在一個Properties里邊,這里只針對win2k以上的,其它系統可以自己改進
public Properties getEnv() throws Exception
{
Properties prop=new Properties();
String OS = System.getProperty("os.name").toLowerCase();
Process p=null;
if(OS.indexOf("windows")>-1)
{
p=Runtime.getRuntime().exec("cmd /c set"); //其它的操作系統可以自行處理, 我這里是win2k
}
BufferedReader br=new BufferedReader(new
InputStreamReader(p.getInputStream()));
String line;
while((line=br.readLine())!=null)
{
int i=line.indexOf("=");
if(i>-1)
{
String key=line.substring(0,i);
String value=line.substring(i+1);
prop.setProperty(key,value);
}
}
return prop;
}
//具體用法
public static void main(String[] args)
{
try
{
SysProb sp=new SysProb();
Properties p=sp.getEnv();
System.out.println(p.getProperty("Path")); //注意大小寫,如果寫成path就不對了
}
catch(Exception e)
{
System.out.println(e);
}
}
}
更多java讀取操作系統環境變量相關文章請關注PHP中文網!
本文原創發布php中文網,轉載請注明出處,感謝您的尊重!
總結
以上是生活随笔為你收集整理的php 获取系统环境变量,java读取操作系统环境变量的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 铺1.5×2.0的床垫褥需要多少斤?
- 下一篇: docker重启后容器消失_docker