Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

launch associated program of file type  RSS feed

 
phase one
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a user clicks on a word document or jpg file I want to launch the associated program that runs that file. In the above example, word and acdsee would run respectively.
How would I do this from JFileChooser or some other Java File Explorer widget.
Thanks,
phase1
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"phase one" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

You can't really find out what programs are associated with what filetypes in the OS, but you can use Runtime.exec() to get Windows to do this. Read this article at JavaWorld to figure out the best way to use Runtime.exec(). Then just specify the file you want to open and the associated program will launch. To get a .png to display in MS Photo Editor I just use the line :


Make the changes specific to your platform and file and it should work.


Thanks! and welcome to the JavaRanch!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!