網站首頁 學習教育 IT科技 金融知識 旅遊規劃 生活小知識 家鄉美食 養生小知識 健身運動 美容百科 遊戲知識 綜合知識
當前位置:趣知科普吧 > IT科技 > 

runtime。exec|java

欄目: IT科技 / 發佈於: / 人氣:1.37W

<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>

java runtime.exec是什麼?讓我們一起來了解一下吧!

首先,java runtime.exec是java程序裏一個很方便的方法,java可以透過運用Runtime.exec()在特定環境和工作目錄的特定進程裏執行外部程序或命令。

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 {undefinedpublic static void main(String[] args) {undefinedtry {undefined// print a messageSystem.out.println("Executing notepad.exe...");// create a file with the working directory we wishFile dir = new File("C:/");// create a process and execute notepad.exe and currect environmentProcess process = Runtime.getRuntime().exec("notepad.exe",null, dir);// print another messageSystem.out.println("Notepad should now open.");} catch (Exception ex) {undefinedex.printStackTrace();}}}

Tags:java