Opening a MS Word file with java

Hi,

I'm trying to write an action performed method in java that will open a specified MS Word file.

I've tried the following (as part of my gui), but when I click the button I get lots of errors.

public void actionPerformed(ActionEvent e) {
            try{
                  
      String command = "\"C:\\Documents and settings\\All users\\Start Menu\\Programs\\Microsoft Office\\Office\\WINWORD.EXE" + "c:\\testingFile.doc" ;
                                                            
      Process p = Runtime.getRuntime().exec(command);
      int exitValue = p.waitFor();
      }catch (Exception x) {
         x.printStackTrace();
      }


Office is stored at:  C:\Documents and Settings\All Users\Start Menu\Programs\Microsoft Office
and the file at: C:\testingFile.doc

any ideas guys?

Thanks
LFC1980Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>WINWORD.EXE"

should have a space:

WINWORD.EXE "
CEHJCommented:
Actually it should be

"\"C:\\Documents and settings\\All users\\Start Menu\\Programs\\Microsoft Office\\Office\\WINWORD.EXE\" " +  "c:\\testingFile.doc" ;
CEHJCommented:
Easiest would be

"C:/DOCUME~1/ALLUSE~1/STARTM~1/Programs/MICROS~1/Office/WINWORD.EXE " + "c:/testingFile.doc";
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

CEHJCommented:
Or

String[] command = { "cmd.exe", "/c", "start", "c:/testingFile.doc" };

You need to execute that in a separate thread really though, or it could block your GUI thread

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LFC1980Author Commented:
I've tried all of these - none seem to work :(
LFC1980Author Commented:
tell a lie, the last one works!
Thanks :)
CEHJCommented:
>>none seem to work

Meaning?
CEHJCommented:
:-)

That's probably the best one. You don't need

>>int exitValue = p.waitFor();
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.