JavaからJava以外のアプリケーションを起動する
import java.io.*;
public class RunNotepad
{
public static void main(String args[]) {
try {
Runtime.getRuntime().exec("c:/Windows/Notepad.exe");
} catch(IOException e) {
System.out.println(e.getMessage());
}
}
}
<実行結果>
Notepadが起動します。
上記のコードではJVMはNotepad起動後に終了してしまいす。
<Runtimeクラス>
Runtime.getRuntime で現在実行中の自アプリケーションの実行環境を入手しています。
入手しているオブジェクトはRuntimeクラスのオブジェクトです。
Runtime.exec 指定された文字列コマンドを、独立したプロセスで実行します。ネイティブなプロセスを作成します。