怎么样用JAVA取得系统的路径? 你查一下相关api,servletContext可能不够用,你再找找别的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 System.getProperty("user.dir");就是了 TO:half00(风中行) 谢谢!不过这个是取工作路径如:F:\SCC\workaround\study-test\easyStruts我想取的是c:\winnt\system32 或 c:\winnt\system也就是取windows系统盘下的系统路径的system或system32这个路径!!!! TO:大家!我是想取操作系统的路径!先不用考虑非WIN系统先解决WINDOWS的就行!大家有好的方法吗? //你在命令行里运行一下 set ,看看System.getProperty("windir"); TO:westwin(newbie)如果用SET肯定是在已知的情况下才可以set而我是想在未知的情况下获取操作系统的路径!!有办法吗? 我原来写过这个程序,用java考几个dll到系统目录下,java api里没有相应的功能,因为java是跨平台的,它的所有api要保证在所有平台下使用.所以可以采取折衷的办法.我原来写的代码忘了,且现在不在手上,你给我一个mail,我找到之后发给你 用Routetime执行set命令,获取如下:SystemRoot=C:\WINNT加\system32 TO:ralphvsclark(微笑) 本来我也有这个想法用JAVA调DLL来获取,谢谢您!我的MAIL:[email protected] 可以加为QQ或MSN好友吗?来邮件时可以写明,我加你! TO:playgb(溯缘)用Routetime执行set命令,获取如下:SystemRoot=C:\WINNT加\system32 这个是什么意思呀!怎么用?可以给个例子或代码吗?MAIL:[email protected] 可以加为QQ或MSN好友吗?来邮件时可以写明,我加你! 有这么复杂吗?试试这个吧System.out.println(System.getenv("windir")); 或者System.out.println(System.getenv("SystemRoot")); 你是不是想取得系统变量定义的东西?我这里有个例子,是我原来取得Tomcat的路径的例子(当时我还不知道有servletContext,所以就自己写了一个,见笑了)代码: /** * * @return */ private String getTomcatPath(){ String strTomcatPath = null; try{ byte[] a = null; Runtime rt = Runtime.getRuntime(); Process p = rt.exec("cmd.exe /c set"); BufferedReader reader = null; //the output goes into process obj reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String result; int iIndex; //getting the result of dos command while ( (result = reader.readLine()) != null){ //你把这个地方改了就行 if ( (iIndex = result.indexOf("CATALINA_HOME=")) >= 0){ strTomcatPath = result.substring(result.indexOf("=") + 1).replace('\\','/'); } } reader.close(); p.waitFor(); } catch (java.io.IOException ie){ //ie.printStackTrace(); } catch (Exception e){ //e.printStackTrace(); } finally{ return strTomcatPath; } }good luck Java默认属性里不包含系统路径。但你可以结合Java和C++来获取,用C++获取系统路径,传给Java. 上面的方法使用JNI技术--Java Native Interface System.out.println(System.getProperties());看那个对你的胃口,就用之。 感谢大家!晚上有时间我测试后再散分!人人有份!但多劳多得!再次感谢大家我还有几个问题没有解决关于JAVA混淆器http://community.csdn.net/Expert/TopicView3.asp?id=3520385关于LOTUS取关系数据库数据(JAVA代理)http://community.csdn.net/Expert/TopicView3.asp?id=3506787关于JAVA/CORBA http://community.csdn.net/Expert/TopicView3.asp?id=3515722请大家帮忙!!! 我想这个是不是需要在java中调用windows的程序来执行了呢?隐藏调用,比如在java中调用dos的某些命令就可以的。 进来帮帮看看,为什么在类的本身创立自己对象不可以这样用的 求助 CRC-ITU校验问题 谁能解释清楚abstract方法为什么不能同时是... 栈溢出的问题? 找一个好的数据包格式 如何学习JAVA 越早做项目越好!如何找项目? 求购CRM系统源代码 无标题 求个java取系统时间的函数 请问一个乱码的问题。急急急!! 一个入门的问题?
\winnt\system32 或 c:\winnt\system也就是取windows系统盘下的系统路径的system或system32这个路径!!!!
System.getProperty("windir");
如果用SET肯定是在已知的情况下才可以set而我是想在未知的情况下获取操作系统的路径!!有办法吗?
所以可以采取折衷的办法.我原来写的代码忘了,且现在不在手上,你给我一个mail,我找到之后发给你
SystemRoot=C:\WINNT加\system32
用Routetime执行set命令,获取如下:
SystemRoot=C:\WINNT
加\system32 这个是什么意思呀!怎么用?可以给个例子或代码吗?MAIL:[email protected] 可以加为QQ或MSN好友吗?来邮件时可以写明,我加你!
System.out.println(System.getenv("windir"));
System.out.println(System.getenv("SystemRoot"));
(当时我还不知道有servletContext,所以就自己写了一个,见笑了)代码:
/**
*
* @return
*/
private String getTomcatPath(){ String strTomcatPath = null; try{
byte[] a = null; Runtime rt = Runtime.getRuntime(); Process p = rt.exec("cmd.exe /c set"); BufferedReader reader = null; //the output goes into process obj
reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String result;
int iIndex;
//getting the result of dos command
while ( (result = reader.readLine()) != null){
//你把这个地方改了就行
if ( (iIndex = result.indexOf("CATALINA_HOME=")) >= 0){
strTomcatPath = result.substring(result.indexOf("=") + 1).replace('\\','/');
}
}
reader.close();
p.waitFor(); } catch (java.io.IOException ie){
//ie.printStackTrace();
} catch (Exception e){
//e.printStackTrace();
} finally{
return strTomcatPath;
} }
good luck
关于JAVA混淆器http://community.csdn.net/Expert/TopicView3.asp?id=3520385
关于LOTUS取关系数据库数据(JAVA代理)http://community.csdn.net/Expert/TopicView3.asp?id=3506787
关于JAVA/CORBA http://community.csdn.net/Expert/TopicView3.asp?id=3515722请大家帮忙!!!