【发布时间】:2023-03-17 13:28:01
【问题描述】:
我正在尝试使用 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 中检查了这个 How to set working directory with ProcessBuilder 线程。但没有任何运气。有人可以帮忙吗?谢谢
【问题讨论】:
标签: java runtime processbuilder