CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  J2SE / 基础类

(急)如何得到系统的环境变量?

楼主youarestupid(neo)2003-08-03 13:39:26 在 Java / J2SE / 基础类 提问

如何得到系统的环境变量? 问题点数: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

相关问题

  • JSP系统环境变量的设置
  • 请问在win2000的环境变量中,administrator的用户变量与系统变量有什么区别??
  • 如何添加操作系统变量让它能显示在系统环境中的系统变量中
  • 请问在BCB中如何取出系统环境变量???
  • jdk环境变量在98系统中如何配置?
  • jdk开发中设置系统环境变量有什么用?
  • 怎么注册系统的环境变量
  • 如何在win2000中添加一个系统环境变量?
  • 在solaris系统中JDK环境变量的配置
  • 菜菜送分:取系统环境变量path问题

关键词

  • getproperty
  • 环境变量
  • then

得分解答快速导航

  • 帖主:youarestupid
  • wdydt163
  • scbb
  • feiyuegaoshan
  • Hodex

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo