如何使一个java程序,一执行,就打开本地某目录下的html文件?比如abc.html, 就像双击打开那样!
答案:3 悬赏:0
解决时间 2021-01-16 03:28
- 提问者网友:暮烟疏雨之际
- 2021-01-15 17:15
如何使一个java程序,一执行,就打开本地某目录下的html文件?比如abc.html, 就像双击打开那样!
最佳答案
- 二级知识专家网友:怀裏藏嬌
- 2021-01-15 18:12
恩,你的命令不正确,怎么会打开呢?
试试我给你的代码吧
import java.io.File;
public class TestRuntime {
public static void main(String args[]) throws Exception
{
File file = new File("abc.html");
Runtime ce=Runtime.getRuntime();
System.out.println(file.getAbsolutePath());
ce.exec("cmd /c start "+file.getAbsolutePath());
}
}
只要在你的同目录下有abc.html,就可以打开了
试试我给你的代码吧
import java.io.File;
public class TestRuntime {
public static void main(String args[]) throws Exception
{
File file = new File("abc.html");
Runtime ce=Runtime.getRuntime();
System.out.println(file.getAbsolutePath());
ce.exec("cmd /c start "+file.getAbsolutePath());
}
}
只要在你的同目录下有abc.html,就可以打开了
全部回答
- 1楼网友:傲气稳了全场
- 2021-01-15 20:11
Runtime ce=Runtime.getRuntime();只是获得了 jvm的运行时环境,如果要获得双击打开的效果,应该要调用window的dll文件,这个我也不是很懂,一般是 把你的 abc.htmL 打印到一个TextAera不就好了么
- 2楼网友:酒醒三更
- 2021-01-15 19:23
Runtime.getRuntime().exec("cmd.exe /c start d:\\generator-output3");
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |