java로 웹 url 이나 어플리케이션 실행시키기.


import java.awt.Desktop;

//웹일경우. 

String exeCmd = "http://qmffjem09.tistory.com";

Desktop.getDesktop().browse(new URI(exeCmd));


//일반 어플리케이션 일경우. 

String exeCmd =  "C:/Windows/System32/cmd.exe";;

Desktop.getDesktop().open(new File(exeCmd));


또는 Runtime 를 이용하는 방법도 있다. 아래 와 같이 하면 실행 시킬수 있다. 

Runtime runtime = Runtime.getRuntime();

// 실행시킬 프로그램

String path = "C:/Program Files/Internet Explorer/IEXPLORE.EXE";

// 실행시키 주소 또는 파일

String cmd = "http://qmffjem09.tistory.com";

String[] cmds = { path,cmd };

try {

runtime.exec(cmds);

} catch (IOException ex) {

ex.printStackTrace();

}

+ Recent posts