java直接调用php文件,和php接收参数

来源:互联网 发布:程序员修炼之道txt 编辑:程序博客网 时间:2024/05/22 04:38
 public String execPHP(String scriptName, String param) {        StringBuilder output = new StringBuilder();        BufferedReader input = null;        String phpPath = "D:/xampp/php/php.exe";        try {            String line;            Process p = Runtime.getRuntime().exec(phpPath + " " +scriptName + " " + param);            input = new BufferedReader(new InputStreamReader(p.getInputStream()));            while ((line = input.readLine()) != null) {                output.append(line);//                p.destroy();//根据系统不同可能需要            }            p.destroy();        } catch (Exception err) {            err.printStackTrace();        }finally{            if(input != null){                try {                    input.close();                } catch (IOException e) {                    e.printStackTrace();                }            }        }        return output.toString();

}

//调用php算法conclusion = runPHP.execPHP(ALGORITHM_RESIDUES_URL,imageResiduesId);
//php接收
$id = $argv[1];
因为此方法是java开进程直接调用php,因此是以内存方式传参

0 0
原创粉丝点击