首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

怎么调用项目中的exe文件

2012-09-09 
如何调用项目中的exe文件?我把一个exe文件复制到Java项目的libs文件夹然后想在程序中调用开启:Java code R

如何调用项目中的exe文件?
我把一个exe文件复制到Java项目的libs文件夹

然后想在程序中调用开启:

Java code
 Runtime.getRuntime().exec("libs/calc.exe");


结果出错说找不到calc.exe:
Cannot run program "libs/calc.exe": CreateProcess error=2, The system cannot find the file specified

求指点.

[解决办法]
探讨
绝对路径是可以的, 但是我就是想要相对路径. 以后会打成jar包

引用:
您写全路径吧。
如果在windows上执行的话,

Java code


Runtime.getRuntime().exec("calc.exe");



就ok。因为calc这个exe在path目录里 :)

[解决办法]
我这有一个获取当前文件的路径的代码 希望对你有帮助
Java code
//www.luger.meimport java.io.File;public class Test2 {      public static void main(String[] args) throws Exception {            System.out.println(Thread.currentThread().getContextClassLoader()                        .getResource(""));            System.out.println(Test2.class.getClassLoader().getResource(""));            System.out.println(ClassLoader.getSystemResource(""));            System.out.println(Test2.class.getResource(""));            System.out.println(Test2.class.getResource("/")); // Class文件所在路径            System.out.println(new File("/").getAbsolutePath());            System.out.println(System.getProperty("user.dir"));    //获得执行文件的绝对路径      }}/*file:/F:/JavaCode/bin/file:/F:/JavaCode/bin/file:/F:/JavaCode/bin/file:/F:/JavaCode/bin/file:/F:/JavaCode/bin/F:\F:\JavaCode*/ 

热点排行