java window 路径_关于windows的绝对路径在java中的疑惑~求解
Runtimesh=Runtime.getRuntime();Stringfilepath="\"D:/ProgramFiles/Tencent/QQ/QQProtect/Bin/QQProtect.exe\""sh.exec("cmd.exe/c"+filepath);這樣的組合是可以在Myeclipse和導出j...
Runtime sh = Runtime.getRuntime();
String filepath = "\"D:/Program Files/Tencent/QQ/QQProtect/Bin/QQProtect.exe\""
sh.exec("cmd.exe /c "+filepath);
這樣的組合是可以在Myeclipse和導出jar文件的時候正常執行的
String filepath = "\"D:/Program Files/Tencent/QQ/QQProtect/Bin/QQProtect.exe\""
sh.exec(filepath);
String filepath2 = "D:/Program Files/Tencent/QQ/QQProtect/Bin/QQProtect.exe" //2
sh.exec(filepath2);
這樣兩種的組合的話在Myeclipse正常執行但是導出jar后無法執行打開QQ的命令
String filepath2 = "D:/Program Files/Tencent/QQ/QQProtect/Bin/QQProtect.exe" //2
sh.exec("cmd.exe /c "+filepath2);
這樣甚至在eclipse中都無法正常執行
試了很多種可能:最后判斷是路徑原因.
因為有像Program Files這樣帶有空格的字符..但是奇怪的是我不是已經把他定義成String了嗎
難道不是一整句都當成一個字符串來看么?
為什么路徑一定要用"cmd.exe /c "+"\"D:/Program Files/Tencent/QQ/QQProtect/Bin/QQProtect.exe\"" 才可以?
String filepath ="D:/Program Files/Tencent/QQ/QQProtect/Bin/QQProtect.exe"
sh.exec(filepath);
像這樣直接引用windows下面的路徑直接調用就不可以~求解 很亂~
展開
總結
以上是生活随笔為你收集整理的java window 路径_关于windows的绝对路径在java中的疑惑~求解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java编程的例子_java编程实例
- 下一篇: qpid java_AMQP与QPID简