如何从Java启动给定文件的默认(本机)应用程序? [英] How to launch the default (native) application for a given file from Java?

查看:146
本文介绍了如何从Java启动给定文件的默认(本机)应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在显示文件列表;即我的Java应用程序(Eclipse RCP)中的xls,doc,pdf,odt等。当用户点击该文件时,我想启动适当的(根据操作系统认为的)本机应用程序,就像在Windows资源管理器或Finder中一样。

I am displaying a list of files; i.e. xls, doc, pdf, odt etc., in my Java application (Eclipse RCP). When the user clicks on the file, I want to launch the appropriate (according to what the OS thinks) native application, just like it happens in Windows Explorer or the Finder.

当我在这里时:显示Finder或Explorer用于不同文件类型的相同图标会很好。

And while I am here: It would be nice to also display the same icons that Finder or Explorer use for the different file types.

是否有库或Eclipse插件为此?

Is there a library or Eclipse plugin for this?

推荐答案

你想要的是 java.awt.Desktop

Desktop.getDesktop().open( file );

这篇关于如何从Java启动给定文件的默认(本机)应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆