java程序调用python程序输出python结果(无参)

java程序调用python程序输出python结果(无参)_第1张图片

具体代码

java代码

@Test
    public void contextLoads() throws IOException, InterruptedException {
        Process pr = Runtime.getRuntime().exec("python C:\\Users\\tianyong\\Desktop\\222.py");
        BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream(),"GBK"));
        String line;
        while ((line = in.readLine()) != null) {
            System.out.println(line);
        }
        in.close();
        pr.waitFor();
    }
python代码

print("你好 world")

 

你可能感兴趣的:(corejava)