简体   繁体   English

如何确定从Java应用程序访问某些第三方程序和资源的方式?

[英]How can I determine the way to access certain third-party programs and resources from my Java app?

I'm trying to open a PDF file after I generate a report. 生成报告后,我试图打开PDF文件。 I mean, the user logs in (it's a Swing-based app) and clicks to generate a report. 我的意思是,用户登录(这是一个基于Swing的应用程序)并单击以生成报告。 Then, a PDF file is generated. 然后,生成PDF文件。 I would like to launch the PDF reader at that moment. 那时候我想启动PDF阅读器。 I could do something like exec("evince "+path_to_pdf_file) . 我可以做类似exec("evince "+path_to_pdf_file) It's just for Ubuntu, Windows would be more difficult. 仅对于Ubuntu,Windows会更困难。 I'm thinking I need to explore the registry. 我想我需要探索注册表。

How can I achieve this? 我该如何实现?

What you need is the method java.awt.Desktop#open 您需要的是方法java.awt.Desktop#open

Launches the associated application to open the file. 启动关联的应用程序以打开文件。 If the specified file is a directory, the file manager of the current platform is launched to open it. 如果指定文件是目录,则启动当前平台的文件管理器以将其打开。

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

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