[英]How can I run the html file in browser using java program?
This is my code. 这是我的代码。 I am able to open browser but it will not load the html source.
我可以打开浏览器,但不会加载html源。
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);
You have too many spaces in the brow
value - I presume that's just a formatting issue in the question. brow
值中的空格过多-我认为这只是问题中的格式设置问题。
Using the single-argument version of exec
splits the input string by spaces, so your code will try to execute a command C:/Program
and pass it arguments "Files"
, "(x86)/Internet"
, "Explorer/iexplore.exeC:/Program"
, "Files"
, etc. 使用
exec
的单参数版本将输入字符串按空格分隔,因此您的代码将尝试执行命令C:/Program
并将其参数"Files"
, "(x86)/Internet"
, "Explorer/iexplore.exeC:/Program"
传递给它。 "Explorer/iexplore.exeC:/Program"
, "Files"
等
Note that "Explorer/iexplore.exeC:/Program"
- because you concatenated the two strings without a space. 请注意,
"Explorer/iexplore.exeC:/Program"
-因为您串联了两个字符串而没有空格。
You could resolve these issues by passing an array of strings to exec()
instead of using the single-string version, but you're better off using Desktop.getDesktop().browse(URI);
您可以通过将字符串数组传递给
exec()
而不是使用单字符串版本来解决这些问题,但是最好使用Desktop.getDesktop().browse(URI);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.