0

我尝试用 java 打开一个 pdf 文件,它在 Windows 上运行良好,但在 Mac 上,如果 pdf 阅读器未打开,则 pdf 无法打开。

我尝试了很多方法来打开文件,例如:

Desktop.getDesktop().open(file);

或者

String[] cmd = new String[]{"/usr/bin/open", file.getPath};
Runtime.getRuntime().exec(cmd);

我还尝试在打开文件之前打开预览(mac pdf阅读器):

String openPreview = "/Applications/Preview.app/Contents/MacOS/Preview";
Runtime.getRuntime().exec(openPreview);
String[] cmd = new String[]{"/usr/bin/open", "-a", "preview", file.getPath};
Runtime.getRuntime().exec(cmd);

但是没有任何工作......我没有其他想法,我不知道为什么它不起作用。

4

0 回答 0