【发布时间】:2015-07-03 18:15:27
【问题描述】:
我想通过使用 apache commons exec 库来运行文件 (a.txt)。但它给了我这个错误:有什么问题?
线程“main”java.io.IOException 中的异常:无法运行程序“a.txt”(在目录“C:\Users\sinaa\Desktop”中):CreateProcess 错误=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);
}
【问题讨论】:
-
您确定该文件存在于您的桌面上吗? “跑”是什么意思?
-
是的,我确定。我的意思是我想在编译代码时在记事本窗口中打开 a.txt。
-
你的意思是 a.txt 不是脚本吗?您只想在记事本中打开 a.txt?
-
是的。与在指定目录中的命令提示符相同,我键入 a.txt 并按 Enter。