java打开并显示文件

来源:互联网 发布:金无怠 知乎 编辑:程序博客网 时间:2024/05/17 08:02

方法一:利用Runtime类(运行时操作类,封装了JVM进程的类)中的exec(String commad)方法执行本机命令

There are four overloaded versions of the exec() command:

  • public Process exec(String command);
  • public Process exec(String [] cmdArray);
  • public Process exec(String command, String [] envp);
  • public Process exec(String [] cmdArray, String [] envp);

Runtime.getRuntime().exec("rundll32 url.dll FileProtocolHandler "+"目标文件绝对路径");


方法二:

java.awt.Desktop.getDesktop().open(new File("目标文件绝对路径"));

二者的区别??欢迎大家评论!!!

原创粉丝点击