runtime.exec 路徑參數含空格的問題

今天開發過程當中遇到一個問題,代碼以下: String phantomjs_env = "D:\phantom js\phantomjs_env\"; String phantomjs_temp = "D:\phantom js\phantomjs_temp\"; String params = phantomjs_env +"phantomjs.exe "; params += phantomjs_env + "highcharts-convert.js " ; params += "-infile "+ option_file_path + " "; params += "-outfile " + out_image_path + "+ "-type png"; Runtime rt = Runtime.getRuntime(); Process p = rt.exec(params);
……省略部分代碼開發

運行時報錯,提示系統找不到制定路徑get

猜想運行時將D:/phantom 看成了第一個參數io

修改代碼以下 String params = """ + phantomjs_env +"phantomjs.exe"+ "" "; params += """ + phantomjs_env + "highcharts-convert.js" + "" "; params += "-infile " + """ + option_file_path + "" "; params += "-outfile " + """ + out_image_path + "" "+ "-type png"; 問題解決phantomjs

關鍵是將參數用雙引號包起來file

相關文章
相關標籤/搜索