我正在尝试使用 Java 中的 xdg-open 命令在 Linux 中打开 PDF 文件。
String[] command = {"xdg-open","\""+path+"\""}
Process p = Runtime.getRuntime().exec(command,null);
p.waitFor();
当我在终端中运行代码时,即使我在终端中输入它也没有任何反应:
xdg-open path
它打开 PDF。 有什么想法吗?
最佳答案
你不应该逃避路径:如果程序被调用,它有一个无效的路径(“path”
而不是 path
)。
String[] command = {"xdg-open", path}
Runtime.getRuntime().exec(command,null);
将在内部使用 ProcessBuilder
,对于 Linux,它应该调用系统命令 execve。
关于java - 使用 Linux 终端在 java 中打开 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52871833/