We help IT Professionals succeed at work.

how to open any file in Java?

saffar4ever
saffar4ever asked
on
I need the code to run/open/execute any word document/picture/... in windows default application in Java.
This may help : Runtime.getRuntime().exec(myFileLocation);
Please help me.
Comment
Watch Question

Commented:
Runtime.getRuntime().exec("cmd /c \""+fileName+"\"");
Bart CremersJava Architect
Commented:
In Java 6 there's support for this.

You can use: java.awt.Desktop.getDesktop().open(new File(myFileLocation));

Prior to Java 6 it's harder to get this right and platform independent.
here is the windows command, which will open the file in appropriate viewer...

rundll32 url.dll,FileProtocolHandler NAME&LOCATION OF THE FILE HERE

you can execute this with Runtime.exec

Author

Commented:
thanks all. sorry for being late. pls give me some more time to test. i had pc problems

Explore More ContentExplore courses, solutions, and other research materials related to this topic.