1. 使用Runtime.getRuntime()执行python脚本文件,推荐使用
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Demo1 { public static void main(String[] args) { // TODO Auto-generated method stub Process proc; try { proc = Runtime.getRuntime().exec("python D:\\demo1.py");// 执行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(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }
参考:https://blog.csdn.net/qq_35240555/article/details/123563947
>>java调用python代码时传入参数:https://blog.csdn.net/weixin_45390999/article/details/118787478
>>替换图层数据源
参考:https://desktop.arcgis.com/zh-cn/arcmap/10.3/analyze/arcpy-mapping/updatingandfixingdatasources.htm(使用 arcpy.mapping 更新和修复数据源)