String[] cmd = new String[5];
cmd[0] = "cmd";
cmd[1] = "/c";
cmd[2] = "start";
cmd[3] = " ";
cmd[4] = filePath;
Process process = Runtime.getRuntime().exec(cmd);
或
Process process = Runtime.getRuntime().exec("cmd /c start \"\" \"E:\\kk sd\\www.txt\"");
调用外部程序来打开一个相应的文件
比如我们要使用Editplus来打开一个远程机器上的文件,可以这样
Runtime.getRuntime().exec("D:\\EditPlus \\EditPlus.exe"+" "+\\\\172.16.1.6\\server1\\SystemErr.log)即
Runtime.getRuntime().exec("外部程序位置"+" "+"要打开的文件").
Desktop dsk=DeskTop.getDesktop();
dsk.open(new File(filePath));