在java中的apache exec上执行命令时遇到问题
我想使用ApacheCommonsExec库运行一个文件(a.txt)。但它给了我一个错误:问题是什么
Exception in thread "main" java.io.IOException: Cannot run program "a.txt" (in directory "C:\Users\sinaa\Desktop"): CreateProcess error=2, The system cannot find the file specified
我的代码是:
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);
}
# 1 楼答案
根据您的评论:
要使用默认关联应用程序在Java中打开文件,请使用Desktop类: