我試圖通過JAVA程序執行帶有一些參數的bat文件。參數是全路徑文件名,而這個路徑具有空間的一些文件夾名稱,創建問題,並給了我下面的錯誤如何使用帶參數的文件名(即具有完整路徑的文件名)運行帶有空格的文件夾名稱的bat文件
Error: 'D:\Documents' is not recognized as an internal or external command
代碼如下
String command = "D:\Documents and Settings\ A.bat" + " " D:\Documents and Settings\B.xml
1. process = Runtime.getRuntime().exec(new String[] {"cmd.exe","/c",command});
2. process.waitFor();
3. exitValue = process.exitValue();
你試過用雙斜槓嗎? String command =「D:\\ Documents and Settings \\ A.bat」+「」D:\\ Documents and Settings \\ B.xml – JackTurky 2012-02-27 14:48:00
*「代碼如下」*最好是僞代碼。無論如何,要回答你的下3(至5)個問題,請閱讀[this](http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html)。 – 2012-02-27 15:17:06
我已經試過這個選項,但沒有運氣 – Abhijeet 2012-02-27 17:05:22