Java执行本地Python脚本

1:add.py

a = 100
b = 200
print (a + b)

2:测试代码

Process proc = Runtime.getRuntime().exec("python D:\project\python\add.py");

            BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
            String line = null;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
            in.close();
            proc.waitFor();

也可以使用jython-standalone工具包实现,详情见:https://www.jython.org/index

原文地址:https://www.cnblogs.com/yshyee/p/14276506.html