如何使用java程序在浏览器中运行html文件?
这是我的密码。我可以打开浏览器,但它不会加载html源代码如何使用java程序在浏览器中运行html文件?,java,Java,这是我的密码。我可以打开浏览器,但它不会加载html源代码 class Browser { public static void main(String[]args) { try { Runtime rtime = Runtime.getRuntime(); String url = "C:/Program Files (x86)/Internet Explorer/DD.html"; Strin
class Browser {
public static void main(String[]args) {
try {
Runtime rtime = Runtime.getRuntime();
String url = "C:/Program Files (x86)/Internet Explorer/DD.html";
String brow = "C:/Program Files (x86)/Internet Explorer/iexplore.exe";
Process pc = rtime.exec(brow + url);
pc.waitFor();
} catch (Exception e) {
System.out.println("\n\n" + e.getMessage());
}
}
}
使用以下命令:
Desktop.getDesktop().browse(URI);
brow
值中的空格太多-我想这只是问题中的格式问题
使用单参数版本的exec
将输入字符串按空格分割,因此您的代码将尝试执行命令C:/Program
,并向其传递参数“文件”
,(x86)/Internet“
,”Explorer/iexplore.exec:/Program“
,“文件”
,等等
请注意,“Explorer/iexplore.exeC:/Program”
——因为您连接了两个字符串,但没有空格
您可以通过将字符串数组传递到
exec()
而不是使用单字符串版本来解决这些问题,但是最好使用您的DD.html是否确实位于Internet Explorer程序目录中?你不应该真的在那里改变任何东西是的,它在internet explorer程序目录中,我得到了我的答案,谢谢你表现出兴趣