
具体代码
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")
本文介绍了一个Java程序如何通过运行时环境调用Python脚本的实例。具体展示了使用Runtime.getRuntime().exec()方法执行Python脚本,并通过输入流读取Python脚本的输出。

被折叠的 条评论
为什么被折叠?



