externally opening a file with the program its associated with

Basically I'm looking to simulate what would happen if you double clicked on something in a windows explorer window. I want to have the operating system open a file with the application that as associated with it.how do I do it?
[250 byte] By [ThisIsRummy] at [2007-9-26 4:20:28]
# 1
Why not just use windows explorer?
darrelln at 2007-6-29 17:23:47 > top of Java-index,Archived Forums,Java Programming...
# 2
I need to do it from inside my java application.
ThisIsRummy at 2007-6-29 17:23:47 > top of Java-index,Archived Forums,Java Programming...
# 3
Do the same thing you would do to execute an external file (ie: an .EXE), except pass the name of the file you want openened. So to open a Word file, execute "MyFile.doc" and windows should handle the rest.
gmagana at 2007-6-29 17:23:47 > top of Java-index,Archived Forums,Java Programming...
# 4

Have you considered the portability issue?

Win - Associate by editable user preferences

Mac - Associate to creation program

Unix/Dos - Explicitly associate program at command

Rather than just using exec, you could look into something encapsulated to set which program to use so you could use on other system.

smh3r at 2007-6-29 17:23:47 > top of Java-index,Archived Forums,Java Programming...
# 5
How about:Runtime.getRuntime().exec("start " + file); where "file" is the absolute path of the file you want to open.
schapel at 2007-6-29 17:23:47 > top of Java-index,Archived Forums,Java Programming...
# 6
just do Runtime.getRuntime().exec(completeFilePath);
raj_rash36 at 2007-6-29 17:23:47 > top of Java-index,Archived Forums,Java Programming...
# 7
but it works only for windows :)
raj_rash36 at 2007-6-29 17:23:47 > top of Java-index,Archived Forums,Java Programming...