通过Java获取Windows文件关联 [英] Get Windows files associations via Java

查看:83
本文介绍了通过Java获取Windows文件关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这将是一件容易的事,但是. . . 我希望我的Java程序获取用户的Windows文件关联. 换句话说,我想知道用户使用什么来打开.txt文件,.cvs文件等. assoc和ftype命令提供该信息,但不为用户提供. 换句话说,如果我将文本编辑器设置为Notepad ++, assoc和ftype不显示它.它们显示系统默认值记事本. 看来我必须从注册表中获取该信息,但是我有两个问题. 1)我不知道要提取的确切注册表项 (尽管我看过"reg查询HKEY_CURRENT_USER,HKEY_CLASSES_ROOT等") 2)我不知道如何从注册表中提取密钥.我看过JNI提到 但还没有弄清楚细节. 任何提示表示赞赏.

I thought this would be an easy task but . . . I want my Java program to get the user's Windows file associations. In other words, I want to know what the user uses to open .txt files, .cvs files, etc. The assoc and ftype commands provide that info, but not for the user. In other words, if I've set my text editor to Notepad++, assoc and ftype don't show it. They show the system default, Notepad, instead. It looks like I have to get that info from the registry but I have two problems. 1) I don't know the exact registry keys I want to pull (though I've looked at "reg query HKEY_CURRENT_USER, HKEY_CLASSES_ROOT, etc.) 2) I don't know how to pull the key from the registry. I've seen JNI mentioned but haven't figured out the details. Any hints appreciated.

推荐答案

看看Eclipse的Program类,该类应符合您的要求:

Take a look at the Eclipse's Program class, which should to what you want: http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fprogram%2FProgram.html.

如果您要启动该程序,请使用桌面类(如MadProgrammer建议的那样)

If you would like to launch the program, use the Desktop-class (like MadProgrammer suggested)

这篇关于通过Java获取Windows文件关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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