Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- asp.net
- javascript
- 웹 서비스
- Eclipse
- Bootstrap
- TextBox
- Java
- MS-SQL
- MANTIS
- 자바
- Apache Lucene
- Android
- jsp
- SpringSource Tool Suite
- WebView
- Redirect
- 컬럼명
- C#
- 안드로이드
- 자바스크립트
- Web Service
- STS
- 이클립스
- scrollView
- Maven
- MSsql
- 웹뷰
- varags
- decompiler
- html
Archives
- Today
- Total
bboks.net™
Java에서 웹 브라우저 띄우기 본문
import java.lang.reflect.Method;
public class BrowserControl {
/**
* Method to Open the Broser with Given URL
*
* @param url
*/
public static void openUrl(String url) {
String os = System.getProperty("os.name");
Runtime runtime = Runtime.getRuntime();
try {
// Block for Windows Platform
if (os.startsWith("Windows")) {
String cmd = "rundll32 url.dll,FileProtocolHandler " + url;
Process p = runtime.exec(cmd);
}
// Block for Mac OS
else if (os.startsWith("Mac OS")) {
Class fileMgr = Class.forName("com.apple.eio.FileManager");
Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class });
openURL.invoke(null, new Object[] { url });
}
// Block for UNIX Platform
// else {
// String[] browsers = {"firefox", "opera", "konqueror", "epiphany",
// "mozilla", "netscape" };
// String browser = null;
// for (int count = 0; count < style="color: rgb(153, 0, 0);">length
// && browser == null; count++)
// if (runtime.exec(new String[] {"which",
// browsers[count]}).waitFor() == 0)
// browser = browsers[count];
// if (browser == null)
// throw new Exception("Could not find web browser");
// else
// runtime.exec(new String[] {browser, url});
// }
} catch (Exception x) {
System.err.println("Exception occurd while invoking Browser!");
x.printStackTrace();
}
}
public static void main(String[] args) {
openUrl("http://javaxden.blogspot.com");
}
}
윈도우에서는 뜨는거 확인했고, 맥이랑 유닉스는 확인 못했씁니다..
[출처] Launch Web Browser through Java