我有一个应该在文本编辑器中打开文档的功能。我使用“打开”命令。使用open命令有效,但是实际打开文档大约需要10秒钟的延迟。当我直接调用文本编辑器(对于Mac为TextEdit)时,文档会快速打开。但是,如果我直接调用应用程序,有时会遇到与权限相关的错误,因此我不想走这条路。有什么想法吗?
private void openNote(String note) {
try {
if (Files.isReadable(Paths.get(note + ".rtf"))) {
ProcessBuilder pb = new ProcessBuilder("/Applications/Atom.app/Contents/MacOS/Atom", note + ".rtf");
pb.redirectErrorStream(true);
pb.directory(new File(notesDir));
final Process p = pb.start();
} else {
System.out.println("File is not writable");
}
} catch (NoSuchElementException e) {
System.out.println("Unable to open note. Error NoSuchElementException: " + e.getMessage());
} catch (IOException e) {
System.out.println("Unable to open note. Error IOException: " + e.getMessage());
}
}