简体   繁体   English

如何指定用于打开Mac OSX的Java System.exec()文档的命令行?

[英]How do I specify a command line to open a document for Java System.exec() for Mac OSX?

I am helping a colleague set up some GUI programming tools I have written in Java. 我正在帮助一位同事设置一些我用Java编写的GUI编程工具。

I need to "open", "start" or "launch" a document using Java System.exec(). 我需要使用Java System.exec()“打开”,“开始”或“启动”文档。 For example, I want to open some text file in the default editor, possibly positioned at line 20, column 50. Or I want to start the default browser and display a particular HTML page. 例如,我想在默认编辑器中打开一些文本文件,可能位于第20行的第50列。或者我想启动默认浏览器并显示特定的HTML页面。

What's the right way to do this? 什么是正确的方法?

You can use Desktop.open() which handles exactly that in an OS-independent manner. 您可以使用Desktop.open()以与操作系统无关的方式精确地处理该问题。
So you do not need to mess around with Runtime.exec() 因此,您无需弄乱Runtime.exec()

Try the "open" command, which opens a file (or URL or directory) just as if you had double-clicked on it, eg: 尝试使用“打开”命令,它会打开一个文件(或URL或目录),就像您双击它一样,例如:

$ open http://slashdot.org # Opens in your web browser
$ open $HOME/foo.txt # Opens in your text editor
$ open $HOME # Opens in the Finder

I have verified that you can use that command with Runtime.exec() . 我已验证您可以将该命令与Runtime.exec()

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

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