(急)如何得到系统的环境变量?
如何得到系统的环境变量? 问题点数:100、回复次数:7Top
1 楼wdydt163(东东)回复于 2003-08-03 13:42:38 得分 10
System.getProperties()Top
2 楼scbb(星际Baby)回复于 2003-08-03 14:13:07 得分 10
import java.util.*;
public class TestEnv {
public static void main(String[] args){
Properties prop = System.getProperties();
Enumeration e = prop.propertyNames();
while(e.hasMoreElements()) {
System.out.println(System.getProperty(e.nextElement().toString()));
}
}
}Top
3 楼feiyuegaoshan(飞跃)回复于 2003-08-03 14:19:58 得分 30
You can't get to the environment variables with pure Java for security
reasons - it was taken out of the API a while ago. If you want to pass
environment information in you'll have to provide -D<variable-name>=<value>
to the java executable, then you can use System.getProperty().
javah will generate C stubs for methods marked using the "native" keyword,
for making calls from java to C. You could always build a bridge to a
library and then call getenv() from the standard C libraries.
If you're working in Win32 then you could write a COM component which
exposes the information you need and use J-Integra (no I don't work for
them) to get access to it from Java.
Top
4 楼wdydt163(东东)回复于 2003-08-03 15:13:37 得分 0
to feiyuegaoshan:
高手啊!!:)Top
5 楼pittzhao(活着)回复于 2003-08-03 15:15:41 得分 0
我的目标→飞跃Top
6 楼lymkelly(柳叶眉)回复于 2003-08-03 16:42:20 得分 0
markTop
7 楼Hodex(小何才露尖尖角)回复于 2003-08-03 16:52:22 得分 50
同意 scbb(星际Baby)
如果你只想得到某一个环境变量的话也可以
System.getProperty("os.name");之类的
Top




