Running a .exe file using Java

前端 未结 4 1599
既然无缘
既然无缘 2020-12-06 15:45

How to run an exe file using java code?The .exe file is already there. The plan is to write a Java code for running the same. Any tutorial or reference for the same?

4条回答
  •  抹茶落季
    2020-12-06 16:26

    The quickest and easiest way is just to do as follows:

    Runtime.getRuntime().exec("yourapp.exe");
    

    Also, see an alternative approach at http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/ProcessBuilder.html

    There is an example there. ProcessBuilder gives you a bit better control over the process and arguments and is probably a bit cleaner and more expressive, particularly if you need to supply arguments, but does result in a few more lines of code.

提交回复
热议问题