Execute a Java program from our Java program

后端 未结 14 1864
名媛妹妹
名媛妹妹 2020-12-01 17:24

I used

Runtime.getRuntime().exec(\"_____\")

but it throws a IOException as below:

java.io.IOException: Create         


        
14条回答
  •  囚心锁ツ
    2020-12-01 17:52

    The answer is simple all you have to do is put the code -

    $ process p = Runtime.getRuntime().exec("javac factorial.java"); in the try catch block
    

    The code would look like this -

    try
    {
    process p = Runtime.getRuntime().exec("javac factorial.java");
    }
    catch(IOException e)
    {
    e.printStackTrace();
    }
    

    Hey I think this should work. Atleast for me it did work

提交回复
热议问题