2015-04-24 154 views
2

Apache的EXEC执行命令我想运行使用阿帕奇百科全书EXEC库文件(a.txt中)。但它给了我这个错误:什么是问题?麻烦在Java

线程“main”异常java.io.IOException:无法运行程序“a.txt”(在目录“C:\ Users \ sinaa \ Desktop”中):CreateProcess error = 2,系统找不到该文件中指定

我的代码是:

public static void main(String[] args) throws IOException 
{ 

    Executor exec = new DefaultExecutor(); 
    File temp=new File("C:\\Users\\sinaa\\Desktop"); 
    exec.setWorkingDirectory(temp); 
    CommandLine s=new CommandLine("a.txt"); 
    exec.execute(s); 
} 
+0

你确定该文件存在您的桌面上? “跑步”是什么意思? – Marvin

+0

是的,我确定。我的意思是当我编译代码时,我想在记事本窗口中打开a.txt。 –

+0

你的意思是a.txt不是脚本吗?你想只在记事本中打开a.txt? – copeg

回答

0

从您的评论:

我想在正打开A.TXT当我编译代码

要打通使用默认关联的应用程序在Java中的文件otepad窗口,使用Desktop类:

try{ 
    Desktop.open("a.txt"); 
}catch(IOException io){ 
    io.printStackTrace(); 
} 
+0

但我想用apache commons exec来做这件事。 –

+0

这是为什么要求? – copeg