如何使用Java打开HTML文件? [英] How to Open HTML file using Java?

查看:396
本文介绍了如何使用Java打开HTML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过Java程序从本地(在我的系统中)打开HTML文件。我尝试了一些程序通过堆栈溢出,但它没有那么多。



对于EG:我有这个小的HTML文件。

 < html> 
< head>
测试申请
< / head>
< body>
这是测试应用程序
< / body>
< / html>

我的Java代码:

 运行时rTime = Runtime.getRuntime(); 
String url =D:/hi.html;
String browser =C:/ Program Files / Internet Explorer / iexplore.exe;
处理pc = rTime.exec(浏览器+网址);
pc.waitFor();

任何解决方案或提示表示赞赏。

我决定使用默认浏览器

 文件htmlFile = new File(url); 
Desktop.getDesktop()。browse(htmlFile.toURI());


I try to open HTML file from local (In my system) by Java program. I tried some of the program got through stack overflow but its not working as much.

For E.G.: I have this small HTML file.

<html>
  <head> 
    Test Application
  </head>
  <body>
     This is test application
  </body>
</html>

My Java code:

Runtime rTime = Runtime.getRuntime();
String url = "D:/hi.html";
String browser = "C:/Program Files/Internet Explorer/iexplore.exe ";
Process pc = rTime.exec(browser + url);
pc.waitFor();

Any solution or tips appreciated.

解决方案

I would prefer to use default browser

File htmlFile = new File(url);
Desktop.getDesktop().browse(htmlFile.toURI());

这篇关于如何使用Java打开HTML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆