I have a problem. Consider a simple java program wherein I get the file path as input. Based on the extension of file I want to launch the associated editor. Example if I give a path of .jpg file then the file should get opened in the editor installed on the machine. I tried using Runtime class which has exec method. I want to identify which is the default editor to open a file given the file extension. How do I do that ? Are there any entries in registry wherein I get what editor is to be launched when you have so n so file extension ?
I will be thankful for any help. Waiting for your replies.
On the other hand if you only want to do this on operating systems where the question is meaningful (i.e. only on Windows) then using Runtime.exec() to execute "cmd /c start yourfilenamegoeshere.ext" will work.
Paul's "cmd" trick is a good one. You can get the same effect with RUNDLL32 ... Google for "java rundll32" for more examples. I'm not sure how you'd choose cmd over rundll or vice versa.
You can test this by just typing a filename into a command window. Try a few extensions and see what happens. My guess is that this uses the very same extension mappings that Windows Explorer uses to open files when you doubleclick.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss