简体   繁体   English

以可移植的方式以编程方式打开文档

[英]Open a document programmatically in a portable way

is the following command working under Unix&Linux? 是在Unix和Linux下运行的以下命令?

ProcessBuilder prcbdoc = new ProcessBuilder("cmd","/C","start", "Documentation.doc");       
            prcbdoc.directory(new File(currentDir+"/docs/"));
            prcbdoc.start();

I'm not sure because of the "cmd" "/c" 我不确定因为"cmd" "/c"

€: €:

What would be an Linux CentOS equivalent command? 什么是Linux CentOS等效命令?

No, it doesn't work. 不,它不起作用。 From Java documentation: 从Java文档:

a command , a list of strings which signifies the external program file to be invoked and its arguments, if any. 一个命令 ,一个字符串列表,表示要调用的外部程序文件及其参数(如果有)。 Which string lists represent a valid operating system command is system-dependent . 哪个字符串列表表示有效的操作系统命令取决于系统 For example, it is common for each conceptual argument to be an element in this list, but there are operating systems where programs are expected to tokenize command line strings themselves - on such a system a Java implementation might require commands to contain exactly two elements. 例如,每个概念参数通常都是此列表中的元素,但是有些操作系统需要程序对命令行字符串本身进行标记 - 在这样的系统上,Java实现可能需要命令才能包含两个元素。

To open a document in a portable manner using AWT : 使用AWT以便携方式打开文档:

if (Desktop.isDesktopSupported())
 Desktop.getDesktop().open(documentPath);

No, this would not work on Linux (or any other Unix, or on the Mac) due to the "cmd /c" and the "start". 不,由于“cmd / c”和“start”,这不适用于Linux(或任何其他Unix或Mac)。 On the Mac, you'd say "open Documentation.doc" .The various Linux desktops have their own versions of the start/open command: gnome-open for the Gnome desktop, and the FreeDesktop semi-standard xdg-open are some possibilities. 在Mac上,你会说"open Documentation.doc" 。各种Linux桌面都有自己的start / open命令版本: gnome-open用于Gnome桌面,FreeDesktop半标准xdg-open是一些可能性。

编号cmd/c仅与窗口相关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM