中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

java調用瀏覽器打開url(支持Mac,Unix,Linux,Windows)

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
import java.lang.reflect.Method;
 
public class OpenUrl {
 
    public static void openURL(String url) {
        try {
            browse(url);
        } catch (Exception e) {
        }
    }
 
    private static void browse(String url) throws Exception {
        // 獲取操作系統的名字
        String osName = System.getProperty("os.name", "");
        if (osName.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 });
        } else if (osName.startsWith("Windows")) {
            // windows
            Runtime.getRuntime().exec(
                    "rundll32 url.dll,FileProtocolHandler " + url);
        } else {
            // Unix or Linux
            String[] browsers = { "firefox", "opera", "konqueror", "epiphany",
                    "mozilla", "netscape" };
            String browser = null;
            for (int count = 0; count < browsers.length && browser == null; count++)
                // 執(zhí)行代碼,在brower有值后跳出,
                // 這里是如果進程創(chuàng)建成功了,==0是表示正常結束。
                if (Runtime.getRuntime()
                        .exec(new String[] { "which", browsers[count] })
                        .waitFor() == 0)
                    browser = browsers[count];
            if (browser == null)
                throw new Exception("Could not find web browser");
            else
                // 這個值在上面已經成功的得到了一個進程。
                Runtime.getRuntime().exec(new String[] { browser, url });
        }
    }
}

標簽: linux 代碼

版權申明:本站文章部分自網絡,如有侵權,請聯系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯系。

上一篇:JS金額格式化

下一篇:使用 java.net.InterfaceAddress 獲取網卡信息