将文件类型与Java Swing应用程序关联 [英] Associate file type with Java Swing application

查看:97
本文介绍了将文件类型与Java Swing应用程序关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Java swing应用程序,我需要将我的程序设置为文件扩展名.mcsd(MIME类型text/mcsd)的默认程序.该必须在Windows上可以运行,并且如果它也可以在OS X/Linux上运行,那就太好了.我对Java有点陌生(3或4个月),所以请不要用各种专家级的话轰炸我.

I am creating a java swing application and I need to set the my program as the default program for the file extension .mcsd (MIME type text/mcsd). This must work on windows, and it would be nice if it worked on OS X/Linux as well. I am somewhat new to java (3 or 4 months) so please don't bombard me with all kinds of expert talk.

我已经看到将自定义文件扩展名与Windows中的Java应用,但我不希望使用Java Web Start.如果可能的话,我也想知道如何设置该文件类型的图标.我发现 exe4j 作为创建.exe和计划使用它,但是,如果不是将convertinf转换为exe的最佳工具,或者有人知道更好的话,请随时告诉我.另一件事:程序打开后,我需要能够从该文件中获取数据.

I have seen associating a custom file extension with java app in windows, but I would prefer not to use the Java Web Start. If possible, I would also like to know how to set the icon of that file type. I have found exe4j as a way of creating the .exe and plan to use it, but if is not the best tool for convertinf to an exe or someone knows something better feel free to tell me. Another thing: I need to be able to get the data from this file after the program has opened.

所以我的问题是: 我该怎么做?

So my question is: how do I do this?

推荐答案

部署应用.与 Java Web Start :

JWS提供了许多吸引人的功能,包括但不限于初始屏幕,桌面集成,文件关联,自动更新..

请参见文件服务演示.有关声明了以下内容的JNLP的示例,请参见文件服务演示.对.zzz文件类型感兴趣.

See the file services demo. for an example of a JNLP that declares an interest in the .zzz file type.

这是在JNLP中声明关联的方式:

This is how the association is declared in the JNLP:

<association
  extensions="zzz"
  mime-type="text/sleepytime" />

JWS由Oracle提供,可在Windows * nix& OS X.

JWS is supplied by Oracle and works on Windows, *nix & OS X.

..但是我不想使用Java Web Start.因为我想拥有一个本机安装程序,它仅安装程序,而无需打开网页或任何其他内容.如果这不是(网络启动)的工作方式,那么我很乐意使用它.

..but I would prefer not to use the Java Web Start. Because I would like to have a native installer that just installs the program, without opening a web page or anything. If that's not how (web start) works, then I'm happy to use it.

JWS通过Web或网络工作.但是,如果您可以从桌面调用URL的打开(到JNLP),则无需打开任何浏览器.

JWS works over the web or a network. But if you can invoke the opening of an URL (to the JNLP) from the desktop, there does not need to be any browser opened.

我会在URL对象上使用openConnection()来执行此操作吗?

Would I do that using openConnection() on a URL object?

我会使用 Desktop BasicService API.

I would use the Desktop or BasicService API.

Desktop.getDesktop().browse(uri);

boolean result = basicService.showDocument(url);

BasicService演示中所述.

As noted in the BasicService demo.

在Java 6+中,显示另一个Web Start启动文件的调用(例如BasicService.showDocument(another.jnlp))将直接传递给JavaWS,而不会显示浏览器窗口.

In Java 6+, a call to show another web start launch file (e.g. BasicService.showDocument(another.jnlp)) will be handed directly to JavaWS, with no browser window appearing.

由于JWS客户端是该文件类型的默认使用者,因此我希望Desktop API始终如此.

I expect this has always been true of the Desktop API, given the JWS client is the default consumer for that file type.

这篇关于将文件类型与Java Swing应用程序关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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