135-1821-9792

java打开本地html文件的方法

今天小编给大家分享的是java打开本地html文件的方法,相信很多人都不太了解,为了让大家更加了解,所以给大家总结了以下内容,一起往下看吧。一定会有所收获的哦。

为嘉黎等地区用户提供了全套网页设计制作服务,及嘉黎网站建设行业解决方案。主营业务为成都网站设计、成都网站建设、嘉黎网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

第一种:Object获取项目中的properties

InputStream in = Object. class .getResourceAsStream( "/com/demo/conf.properties" );

第二种:直接获得本地配置文件properties

FileInputStream in = new FileInputStream("D:\\work\\demo\\conf.properties"); 
//加载properties文件
Properties prop =  new  Properties();
prop.load(in);
//从配置文件中获取 页面的位置,此处url为网页的绝对路径并解决乱码,如:d:/demo/index.html
 String url = new String(prop.getProperty( "csv_url" ).trim().getBytes("ISO-8859-1"),"gbk");
//根据url打开网页
private static void browse(String url) throws ClassNotFoundException, IllegalAccessException,
IllegalArgumentException, InterruptedException, InvocationTargetException, IOException,NoSuchMethodException {
  String osName = System.getProperty("os.name", "");
    if (osName.startsWith("Windows")) {
        Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
          } else 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 {
                      //  Unix or Linux
                          String[] browsers = { "firefox", "opera", "konqueror", "epiphany", 
                          "mozilla", "netscape" };
    String browser = null;
        for (int count = 0; count < browsers.length && browser == null; count++)
        if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }).waitFor() == 0)
        browser = browsers[count];
        if (browser == null)
        throw new NoSuchMethodException("Could not find web browser");
        else
              Runtime.getRuntime().exec(new String[] { browser, url });
                }}

关于java打开本地html文件的方法就分享到这里了,希望以上内容可以对大家有一定的参考价值,可以学以致用。如果喜欢本篇文章,不妨把它分享出去让更多的人看到。


分享文章:java打开本地html文件的方法
本文路径:http://kswsj.com/article/jphjhp.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号