我希望使用计算机上安装的相关程序(在本例中,使用 MS Word 或 Open Office Writer)从 Java 应用程序打开一个文件(比如说,一个 word 文档)。
问题是我想等到这个子进程完成,这可以使用 Process 类中的 waitFor() 方法来完成。
String executable = findAssociatedApplicationPath(); //for example, returns "C:\\Program Files\\Microsoft Office\\Office12\\msword.exe"
Process p = Runtime.getRuntime().exec(executable + " " + filepath);
p.waitFor();
有人可以告诉我如何编写 findAssociatedApplicationPath() 方法以便返回正确的可执行文件吗?还是有其他方法可以做到这一点?