首页 > 编程语言 > 详细

java执行python文件的方法

时间:2020-03-19 21:30:28      阅读:64      评论:0      收藏:0      [点我收藏+]
 1 public static void A(String pythonPath, String pyPath){
 2   Process proc;
 3   String[] arg = new String[] { "python3", "后缀为.py的文件", "参数1", "参数2", "参数3" }; // 参数可继续增加,但是有长度限制
 4   try {
 5     proc = Runtime.getRuntime().exec(arg);
 6     System.out.println("执行成功,开始输出参数:");
 7     BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
 8     String line = null;
 9     while ((line = in.readLine()) != null) {
10       System.out.println(line);
11     }
12     in.close();
13     proc.waitFor();
14   } catch (IOException e) {
15     e.printStackTrace();
16   } catch (InterruptedException e) {
17     e.printStackTrace();
18   }
19 }

 

java执行python文件的方法

原文:https://www.cnblogs.com/52KT9/p/12526931.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!