乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      java程序中指定某個瀏覽器打開網(wǎng)頁的實現(xiàn)方法

       一本正經(jīng)地胡鬧 2019-04-15

      本文主要介紹的是利用java程序打開指定某個的瀏覽器

      方法一:

      1. import java.lang.reflect.Method;
      2. //實現(xiàn)打開瀏覽器并跳到指定網(wǎng)址的類
      3. public class TestUrl {
      4. public static void openURL(String url) {
      5. try {
      6. browse(url);
      7. } catch (Exception e) {
      8. }
      9. }
      10. private static void browse(String url) throws Exception {
      11. // 獲取操作系統(tǒng)的名字
      12. String osName = System.getProperty("os.name", "");
      13. if (osName.startsWith("Mac OS")) {
      14. // 蘋果的打開方式
      15. Class fileMgr = Class.forName("com.apple.eio.FileManager");
      16. Method openURL = fileMgr.getDeclaredMethod("openURL",new Class[] { String.class });
      17. openURL.invoke(null, new Object[] { url });
      18. } else if (osName.startsWith("Windows")) {
      19. // windows的打開方式。
      20. Runtime.getRuntime().exec(
      21. "rundll32 url.dll,FileProtocolHandler " + url);
      22. } else {
      23. // Unix or Linux的打開方式
      24. String[] browsers = { "firefox", "opera", "konqueror", "epiphany",
      25. "mozilla", "netscape" };
      26. String browser = null;
      27. for (int count = 0; count < browsers.length && browser == null; count++) {
      28. // 執(zhí)行代碼,在brower有值后跳出,
      29. // 這里是如果進程創(chuàng)建成功了,==0是表示正常結束。
      30. if (Runtime.getRuntime()
      31. .exec(new String[] { "which", browsers[count] })
      32. .waitFor() == 0)
      33. browser = browsers[count];
      34. if (browser == null)
      35. throw new Exception("Could not find web browser");
      36. else
      37. // 這個值在上面已經(jīng)成功的得到了一個進程。
      38. Runtime.getRuntime().exec(new String[] { browser, url });
      39. }
      40. // 主方法 測試類
      41. }
      42. }
      43. public static void main(String[] args) {
      44. // 這里填寫你的網(wǎng)址
      45. String url = "xxx";
      46. openURL(url);
      47. }
      48. }

      方法二:

      使用默認瀏覽器打開:

      1. String site = "www.baidu.com";
      2. try {
      3. Desktop desktop = Desktop.getDesktop();
      4. if (desktop.isDesktopSupported()
      5. && desktop.isSupported(Desktop.Action.BROWSE)) {
      6. URI uri = new URI(site);
      7. desktop.browse(uri);
      8. }
      9. } catch (IOException ex) {
      10. System.out.println(ex);
      11. } catch (URISyntaxException ex) {
      12. System.out.println(ex);
      13. }

      方法三:

      通過獲取環(huán)境變量的瀏覽器路徑,然后啟動瀏覽器

      1. String firefox = "C:\\Program Files\\Mozilla Firefox\\firefox.exe";
      2. Map map = System.getenv();
      3. for (Iterator itr = map.keySet().iterator(); itr.hasNext();) {
      4. String value = (String) map.get((String) itr.next());
      5. if (value.contains("firefox.exe")) {
      6. firefox = value;
      7. break;
      8. }
      9. }
      10. Runtime.getRuntime().exec(new String[] { firefox, "www.baidu.com" });

      方法四:

      js方式:

      <scripttype="text/javascript">
      window.onload=function(){
      var WSH = new ActiveXObject("WScript.Shell"); 
        WSH.Run("chrome.exe www.baidu.com"); 
      }
         
      </script>

      // 自動關閉瀏覽器
      Runtime.getRuntime().exec("taskkill /F /IM 360se.exe");

      轉(zhuǎn)載請注明出處:http://blog.csdn.net/l1028386804/article/details/49334975

      1. package com.lyz.test;
      2. import java.awt.Desktop;
      3. import java.io.IOException;
      4. import java.net.URI;
      5. import java.net.URISyntaxException;
      6. /**
      7. * @author liuyazhuang
      8. * @time 2015-10-22
      9. *
      10. */
      11. public class Gotourl {
      12. /**
      13. * 打開IE瀏覽器訪問頁面
      14. */
      15. public static void openIEBrowser(){
      16. //啟用cmd運行IE的方式來打開網(wǎng)址。
      17. String str = "cmd /c start iexplore http://blog.csdn.net/l1028386804";
      18. try {
      19. Runtime.getRuntime().exec(str);
      20. } catch (IOException e) {
      21. e.printStackTrace();
      22. }
      23. }
      24. /**
      25. * 打開默認瀏覽器訪問頁面
      26. */
      27. public static void openDefaultBrowser(){
      28. //啟用系統(tǒng)默認瀏覽器來打開網(wǎng)址。
      29. try {
      30. URI uri = new URI("http://blog.csdn.net/l1028386804");
      31. Desktop.getDesktop().browse(uri);
      32. } catch (URISyntaxException e) {
      33. e.printStackTrace();
      34. } catch (IOException e) {
      35. e.printStackTrace();
      36. }
      37. }
      38. public static void main(String[] args) {
      39. openIEBrowser();
      40. openDefaultBrowser();
      41. }
      42. }


        本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多