今天爱分享给大家带来java 调用python并传参的方法【附代码】,希望能帮助到大家。
public String executePython(String fromPath, String toPath, String picPath, String fileName) {
String success = "500";
String exe = "python";
//要执行python文件的位置
String command = "D:\\pythonProject\\python.py";
//fromPath, toPath, picPath, fileName -->传递给python的参数
String[] cmdArr = new String[]{exe, command, fromPath, toPath, picPath, fileName};
Process process = null;
try {
process = Runtime.getRuntime().exec(cmdArr);
InputStream is = process.getInputStream();
DataInputStream dis = new DataInputStream(is);
//视频处理完成 返回1
String result = dis.readLine();
log.info("python返回结果:" + result);
process.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
return success;
}
python中获取参数
fromPath = argv[1] toPath = argv[2] dirPath = argv[3] txt_path = argv[4]
原文链接:https://blog.itblood.com/1653.html,转载请注明出处。

![和妹妹一起生活吧 官方中文版 [新官中][电脑/1.4G]和妹妹一起生活吧 官方中文版(妹ちゃんとくらそう) [热门SLG/中文/动态]](/wp-content/uploads/replace/2025/07/19/dd28add336d68ffa9ba5f42595d05bfa.webp)