• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Open file using default editor

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hell friends, sir , madam

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.
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear sir,

i'd say that this is too os-dependent to be solvable with java...

best regards,
jan
 
Sheriff
Posts: 27465
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, easy integration with native applications is a feature for Java 6.0 and up and comming.

http://java.sun.com/developer/JDCTechTips/2005/tt0505.html
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic