有没有办法用java获得windows的设置的系统参数的值。

yangzi 2003-05-07 01:08:50
比如,我定义了TOMCAT_HOME = "c:\tomcat",

我有没有办法通过tomcat_home 取得 "c:\tomcat"

我的意思是 有没有这样的函数 String strPath = function("TOMCAT_HOME")
...全文
73 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
superLee 2003-05-08
  • 打赏
  • 举报
回复
用C实现吧,然后再java中调用。
^_^
yangzi 2003-05-07
  • 打赏
  • 举报
回复
o,Ok, I am known,thanks.
井中老男孩 2003-05-07
  • 打赏
  • 举报
回复
不能获得,也没有这样的函数,不过要想实现也可以,运行程序时用参数

java -D TOMCAT_HOME=%TOMCAT_HOME%
yangzi 2003-05-07
  • 打赏
  • 举报
回复
no , Please test my post code, you will find it return NULL.



please test!!
希偌 2003-05-07
  • 打赏
  • 举报
回复
怎么发现楼主回答自己的问题?解决问题了吗?
xys2003 2003-05-07
  • 打赏
  • 举报
回复
// Get all system properties
Properties props = System.getProperties();

// Enumerate all system properties
Enumeration enum = props.propertyNames();
for (; enum.hasMoreElements(); ) {
// Get property name
String propName = (String)enum.nextElement();

// Get property value
String propValue = (String)props.get(propName);


应该可以
lotofu 2003-05-07
  • 打赏
  • 举报
回复
System.getProperties();
没试过,也许可以!
yangzi 2003-05-07
  • 打赏
  • 举报
回复
取不到啊。
设置一下windows环境变量,然后你试下面的代码:
import java.util.Properties;
public class getSystemProperties
{
public static void main(String args[])
{
Properties prop = new Properties(System.getProperties() );
// prop.list(System.out);
System.out.println(System.getProperty("TOMCAT_HOME"));
}
}
bluesmile979 2003-05-07
  • 打赏
  • 举报
回复
System.getProperties();
CoolRay 2003-05-07
  • 打赏
  • 举报
回复
// Get all system properties
Properties props = System.getProperties();

// Enumerate all system properties
Enumeration enum = props.propertyNames();
for (; enum.hasMoreElements(); ) {
// Get property name
String propName = (String)enum.nextElement();

// Get property value
String propValue = (String)props.get(propName);
}
CoolRay 2003-05-07
  • 打赏
  • 举报
回复
System.getProperties().list(System.out);
http://www.chinajavaworld.net/doc/lang/37.html

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧