java runtime.exec是什么?让我们一起来了解一下吧!
首先,java runtime.exec是java程序里一个很方便的方法,java可以通过运用Runtime.exec()在特定环境和工作目录的特定进程里执行外部程序或命令。
java runtime.exec有下面几种调用方法:
* public Process exec(String command); * public Process exec(String [] cmdArray); * public Process exec(String command, String [] envp); * public Process exec(String [] cmdArray, String [] envp);
实战演练,具体步骤如下:
* Java Runtime exec()方法 */ import java.io.File; public class RuntimeDemo {undefined public static void main(String[] args) {undefined try {undefined // print a message System.out.println("Executing notepad.exe..."); // create a file with the working directory we wish File dir = new File("C:/"); // create a process and execute notepad.exe and currect environment Process process = Runtime.getRuntime().exec("notepad.exe", null, dir); // print another message System.out.println("Notepad should now open."); } catch (Exception ex) {undefined ex.printStackTrace(); } } }
以上就是小编今天的分享了,希望可以帮助到大家。