第一种方法,使用Jython
PythonInterpreter interpreter = new PythonInterpreter();
InputStream filePy = new FileInputStream("/root/jni/py/hello.py");
interpreter.execfile(filePy);
filePy.close();
使用到PythonInterpreter执行python脚本
第二种方法,使用Process进程执行
String[] arg = new String[]{"python","/root/jni/py/hello.py","1","2","3","4"};
Process process = Runtime.getRuntime().exec(arg);
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
process.waitFor();
System.out.println("end");