Runtime class in java

后端 未结 6 960
野性不改
野性不改 2020-12-18 12:03

How to execute a java program with the help of Runtime.getRuntime().exec(). For example we shall have the java file path as c:/java/abc.java. Please help me with the code.

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 12:48

    String path1 = "f://" + File.separator+username+File.separator+progName; 
    Runtime runtime = Runtime.getRuntime();
    String command = "javac -classpath " + path + " " + path1;
    System.out.println(command);
    Process process = runtime.exec(command);
    InputStream error = process.getErrorStream();
    

提交回复
热议问题