java调用python 不用使用第三方库
java调用python过程中解决python第三方库问题_wangxf0812的博客-CSDN博客_java调用python第三方库
python中字符串拼接
Pyhton:字符串拼接_北漠220的博客-CSDN博客
java代码:
package hello;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args) throws IOException, InterruptedException, IOException {
String a = "hello";
String b = "world";
//通过原生方式调用,解决python文件引入第三方库的问题
//第一个参数默认是python,第二个参数python脚本路径,第三和第四个参数是python要接收的参数
String[] argg = new String[] { "python", "D:/xm/hello.py", a,b};
Process pr = Runtime.getRuntime().exec(argg);
BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line;
String result = "";
//接收返回结果
while ((line = in.readLine()) != null) {
result += line;
}
System.out.println(result);
in.close();
pr.waitFor();
}
}
Python代码:
import sys
a = sys.argv[1]
b = sys.argv[2]
print("你好世界,{},{}".format(a,b))