永发信息网

如何使一个java程序,一执行,就打开本地某目录下的html文件?比如abc.html, 就像双击打开那样!

答案:4  悬赏:0  手机版
解决时间 2021-02-14 04:00
  • 提问者网友:骨子里的高雅
  • 2021-02-13 13:34
如何使一个java程序,一执行,就打开本地某目录下的html文件?比如abc.html, 就像双击打开那样!
最佳答案
  • 五星知识达人网友:等灯
  • 2021-02-13 14:57
如何使一个java程序,一执行,就打开本地某目录下的html文件?比如abc.html, 就像双击打开那样! 15
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(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-02-13 18:31
恩,你的命令不正确,怎么会打开呢? 试试我给你的代码吧 import java.io.File; public class TestRuntime { public static void main(String args[]) throws Exception { File file = new File("abc.html"); Runtime ce=R.
  • 2楼网友:鱼芗
  • 2021-02-13 16:58
恩,你的命令不正确,怎么会打开呢? 试试我给你的代码吧 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,就可以打开了
  • 3楼网友:神鬼未生
  • 2021-02-13 16:15
你用这个打开试试,意思就是打开cmd执行个打开文件命令 Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", "D:/my local/测试用例.xls"});
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯