独立于平台的方式来按文件类型启动外部应用程序/帮助程序?

发布于 2024-09-12 07:46:50 字数 202 浏览 2 评论 0原文

例如,我正在开发的一个应用程序将 PDF 文件存储到数据库中,然后可以将它们拉出来进行显示。我在那里接到一个电话,使用 Runtime.exec 执行“cmd /c start ”加上 PDF 文件名。非常适合 Windows。不过,我们更愿意找到一种独立于平台的方式(尝试使用各种操作系统的替代方法来避免操作系统检测)来做到这一点,因为我们也在 Solaris 和 Mac 上运行该软件。

For example, one application that I'm working on stores PDF files into a database, then can pull them back out for display. I've got a call in there using Runtime.exec to do a "cmd /c start " plus the PDF filename. Works great for Windows. Would prefer to find a platform independent way (trying to avoid OS detection with alternate methods for various OS) to do this though as we also run the software on Solaris and Mac.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

-小熊_ 2024-09-19 07:46:50

查看 桌面 它有一个开放的方法并且是独立于平台的。

启动关联的应用程序
打开文件。

Look at Desktop which has a open method and that would be platform independent.

Launches the associated application to
open the file.

二智少女猫性小仙女 2024-09-19 07:46:50

我有兴趣看看是否有一个“正确”的答案。如果我要这样做,我会有一个操作系统的属性文件映射到运行所需的命令,然后在运行时解析操作系统。

例如在属性文件中:

windows=cmd /c start
mac=open #(I think)
linux=... etc

I'd be interested to see if there is a 'correct' answer for this. If I were to do this, I'd have a properties file mapping of OS to the command needed to run, and then resolve the OS at runtime.

Eg in a properties file:

windows=cmd /c start
mac=open #(I think)
linux=... etc
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文