凉水代码

Code Cold Water

导航

Java打开系统文件

Posted on 2010-06-24 22:36  凉水代码  阅读(318)  评论(0编辑  收藏  举报
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(
"外部程序位置"+" "+"要打开的文件").
在JDK6中可以使用如下方式:

Desktop dsk=DeskTop.getDesktop();
dsk.open(
new File(filePath));