我正在尝试从另一个 java 程序(exec.java)运行一个 java 文件(editor.java)。它需要输入并显示文件未找到消息。请给我建议,通过它我成功运行程序。
import java.io.*;
public class exec {
public static void main(String argv[]) {
try {
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("Enter the java class name");
String s=br.readLine();
String[] cmd = {"java", "-cp", "E:\netbeans\Project\src", s};
Process pro=Runtime.getRuntime().exec(s);
try (BufferedReader in = new BufferedReader(new InputStreamReader(pro.getInputStream()))) {
String line=null;
while((line=in.readLine())!=null) {
System.out.println(line);
}
}
} catch(Exception err) {
err.printStackTrace();
}
}
java.io.IOException: Cannot run program "editor.java": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at java.lang.Runtime.exec(Runtime.java:615)
at java.lang.Runtime.exec(Runtime.java:448)
at java.lang.Runtime.exec(Runtime.java:345)
at project.exec.main(exec.java:18)