如何打开给定文件的用户系统首选编辑器? [英] How to open user system preferred editor for given file?

查看:150
本文介绍了如何打开给定文件的用户系统首选编辑器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何打开给定文件的系统首选编辑器。

I'm trying to figure out how to open the system preferred editor for a given file.

说,我们有一个用Java编写的文件管理器。用户转到文件夹并查看文件列表。而且,例如,有一个文件 Icon.jpg 。用户双击文件名和文件将在系统首选编辑器(即Gimp)中打开。主要问题是 - 如何做?

Say, we have a file manager, written in Java. User goes to folder and sees the list of files. And, for example, there is a file Icon.jpg. User double clicks on the filename and file opens in system's preferred editor (i.e. Gimp). The main issue is - how to do that?

我们可以做$ code Runtime.getRuntime()。exec(something file),但是这样你应该知道哪个程序在用户环境中是首选的。但是如何?

We can do Runtime.getRuntime().exec("something file"), but this way you should know which program is preferred in user environment. But how?

我们也可以做到$ code Desktop.getDesktop()。edit(File file)这样我们无法跟踪进程,并且无法知道这个子进程是关闭的。其他问题 - 功能在linux上不起作用(至少在Ubuntu 8.10上)。还有 Desktop.getDesktop()。open(文件文件),但它强制打开文件查看器,而不是该文件类型的系统查看器。

We also are able to do Desktop.getDesktop().edit(File file), but this way we cannot track process and aren't able to know then this child process is closed. Other issue - function doesn't work on linux (at least on Ubuntu 8.10). There is also Desktop.getDesktop().open(File file), but it forces to open file viewer, instead of system viewer for that file type.

我正在全周寻找解决方案,但没有任何合适和通用的解决方案。你知道这个问题的其他方法吗?对于我的项目,如果它可以在Windows + Linux + Mac上工作就够了。

I am searching for a solution all week, but didn't got any suitable and generic one. Do you know the other approaches to this question? For my project it would be enough if it would work on Windows+Linux+Mac.

感谢您的答案和建议。

2009-02-08 23:04编辑

Edit on 2009-02-08 23:04

其他建议:我可以强制应用程序选择窗口Windows和Linux,如Mac在打开文件?例如,然后您尝试打开文件,您被要求从系统首选列表中选择应用程序? (Windows资源管理器中的Open with ...)。你知道吗?

Other suggestion: can I force "application selection" window in Windows and in Linux, as in Mac with "open file"? For example, then you trying to open file, you are being asked to choose application from list of system preferred ones? (something like "Open with..." in Windows explorer). Do you know?

推荐答案

看来,如果你不能使用 java.awt.Desktop 你必须区分操作系统:
Windows:

Seems that if you can't use java.awt.Desktop you have to distinguish between the OSes: Windows:

RUNDLL32.EXE SHELL32.DLL,OpenAs_RunDLL <file.ext>

Linux:

edit <file.ext>

Mac:

open <file.ext>

HTH。显然,这不是很便携...

HTH. Obviously, that is not very portable...

这篇关于如何打开给定文件的用户系统首选编辑器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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