现在的位置: 首页 > 综合 > 正文

java打开并显示文件

2013年10月20日 ⁄ 综合 ⁄ 共 427字 ⁄ 字号 评论关闭

方法一:利用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("目标文件绝对路径"));

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

抱歉!评论已关闭.