我正在尝试使用ProcessBuilder运行位于C:/Software/的名为test.pdf的文件。以下是我的代码:
public static void main(String[] args) throws IOException {
ProcessBuilder pb = new ProcessBuilder("test.pdf");
pb.directory(new File("C:/Software/"));
pb.start();
}
我遇到了以下异常:
Exception in thread "main" java.io.IOException: Cannot run program "test.pdf" (in directory "C:\Software"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at com.test.Test.main(Test.java:12)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 2 more
我查看了stackoverflow上的这个帖子:如何使用ProcessBuilder设置工作目录,但没有成功。有人可以帮忙吗?谢谢。