Utilising a file association in a Java application

℡╲_俬逩灬. 提交于 2019-11-27 09:35:11

I'm not positive, but I'd expect that the name of the file you're processing by file click will end up in the arguments to your main() method. Have you tried/checked that?

If this is on Windows (you didn't specify):

In the registry wherever you specified your application path for the file type registered to it, add to "%1". This is a special parameter Windows will fill in with the path of the file that was clicked. So your registry entry would look something like c:\path\to\app.exe "%1"

One way to do this is to have the file association run your Java app via a script or batch file, and have the batch file pass the pathname of the file as a command line argument, environment variable or Java property.

Extensions can be linked to applications, you can setup the registry keys during installation. Which keys you need is documented here:

http://support.microsoft.com/?scid=kb%3Ben-us%3B185453&x=6&y=11

From java you can't access the windows registry in a direct way. Using Runtime you could do something like that http://www.rgagnon.com/javadetails/java-0480.html

There're two commands on Windows that can help, assoc and ftype, so that you needn't do the dirty laundry to manipulate registry. Invoke the commands using, say, java.lang.Process. http://www.rgagnon.com/javadetails/java-0592.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!