我是靠谱客的博主 动人老师,这篇文章主要介绍java如何打开本地html文件,现在分享给大家,希望可以做个参考。

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

复制代码
1
InputStream in = Object. class .getResourceAsStream( "/com/demo/conf.properties" );
登录后复制

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

(推荐学习:java视频教程)

复制代码
1
2
3
4
5
6
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");
登录后复制
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//根据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入门教程

以上就是java如何打开本地html文件的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是动人老师最近收集整理的关于java如何打开本地html文件的全部内容,更多相关java如何打开本地html文件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(94)

评论列表共有 0 条评论

立即
投稿
返回
顶部