자바 디폴트 브라우저 기동시키기(java default browser start)예제소스

홈 > 공유팁! > 프로그램 관련
프로그램 관련

자바 디폴트 브라우저 기동시키기(java default browser start)예제소스

꽁스짱 0 1309
자바로 디폴트 브라우저 기동시키기(java default browser start)예제소스입니다. 자바공부 열심히 하세요~
 
package onj;
 
import java.io.IOException;
 
public class MyBrowser {
 public static void main(String[] args) {
  displayURL();
 }
 
    public static void displayURL() {   
        String cmd = null;
        try {
            if (System.getProperty("os.name").startsWith("Windows")) {              
                cmd = "rundll32 url.dll,FileProtocolHandler http://www.oraclejavanew.kr";
                Process p = Runtime.getRuntime().exec(cmd);
            } else {
             // 유닉스라면 netscape -remote openURL(http://www.oraclejavanew.kr)               
                Process p = Runtime.getRuntime().exec("netscape -remote openURL(http://www.oraclejavanew.kr)");
                try {
                    // waitFor의 결과코드값이 0 이면 브라우저 떠있는 것, 아니면 브라우저 시작 시킴
                    if (p.waitFor() != 0) {
                        cmd = "netscape http://www.oraclejavanew.kr";
                        p = Runtime.getRuntime().exec(cmd);
                    }
                } catch(InterruptedException x) {
                    System.err.println("Error :: " + cmd);
                    System.err.println("Caught: " + x);
                }
            }
        } catch(IOException e) {
            System.err.println("browser invoke error :: " + cmd + e);
        }
    }  
}




0 Comments
제목