• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

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
0
LFC1980
Asked:
LFC1980
  • 6
  • 2
1 Solution
 
CEHJCommented:
>>WINWORD.EXE"

should have a space:

WINWORD.EXE "
0
 
CEHJCommented:
Actually it should be

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

"C:/DOCUME~1/ALLUSE~1/STARTM~1/Programs/MICROS~1/Office/WINWORD.EXE " + "c:/testingFile.doc";
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
0
 
LFC1980Author Commented:
I've tried all of these - none seem to work :(
0
 
LFC1980Author Commented:
tell a lie, the last one works!
Thanks :)
0
 
CEHJCommented:
>>none seem to work

Meaning?
0
 
CEHJCommented:
:-)

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

>>int exitValue = p.waitFor();
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now