Ich muss Ergebnisse von Python ausgeführtem Code in Java verwenden. Ich habe jython jars heruntergeladen. Ich lese unter Teil Code aus dem Internet. Aber die Fehlerreflektor ist Python: kann Datei 'IBM.py' nicht öffnen: [Errno 2] keine solche Datei oder Verzeichnis. Wo sucht es nach der Datei? Meine Datei wird in Pycharm-Projekten erstellt.Fehler beim Aufruf der Python-Datei aus Java-Code und beim Abrufen des Ergebnisses
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CallPython {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String s = null;
// TODO Auto-generated method stub
Process p = Runtime.getRuntime().exec("python IBM.py");
System.out.println("ayush");
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
}}
danke! obwohl ich das früher erkennen konnte. –