Execute a Java program from our Java program

后端 未结 14 1827
名媛妹妹
名媛妹妹 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:54

    public class Test {    
      public static void main(String[] args) throws Exception {    
        Process p = Runtime.getRuntime().exec("\"c:/program files/windows/notepad.exe\"");
        p.waitFor();
      }
    
    }
    

    The above works quite well, instead of passing \"c:/program files/windows/notepad.exe\" as the arguments for the executable, use the path to your program, I'm not sure if this solution is JVM version dependent, or if it can use relative paths.

提交回复
热议问题