今天开发过程中遇到一个问题,代码如下: 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);
……省略部分代码
运行时报错,提示系统找不到制定路径
猜测运行时将D:/phantom 当作了第一个参数
修改代码如下 String params = """ + phantomjs_env +"phantomjs.exe"+ "" "; params += """ + phantomjs_env + "highcharts-convert.js" + "" "; params += "-infile " + """ + option_file_path + "" "; params += "-outfile " + """ + out_image_path + "" "+ "-type png"; 问题解决
关键是将参数用双引号包起来