how to open any file in Java?

Posted on 2008-01-25
Medium Priority
Last Modified: 2008-03-18
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.
Question by:saffar4ever

Assisted Solution

ysnky earned 664 total points
ID: 20742303
Runtime.getRuntime().exec("cmd /c \""+fileName+"\"");
LVL 13

Assisted Solution

by:Bart Cremers
Bart Cremers earned 664 total points
ID: 20742309
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.
LVL 26

Accepted Solution

ksivananth earned 672 total points
ID: 20742354
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 Comment

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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question