• Post Reply Bookmark Topic Watch Topic
  • New Topic

open a word document from my application  RSS feed

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

say I know the location of a specific word document on my local computer (C:/myFolder) how can I open the file directly from my program?

I don't want to read it (or get its content) I need to open it as a Word Doc.

(I guess there's somthing with the runtime but I'm not sure)

thanks
peter
 
Fahd Shariff
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the Runtime class.

e.g
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also Google for "java exec rundll32". You give this technique a filename and it goes through the same mechanism Windows goes through to open a file when you double click on it. That is, if MS Word is the default application for extension "doc" it will open Word. Be aware it might fire up Open Office or some other app if the user has associated the extension differently. That might be a good thing or a bad thing depending on your requirements.

To see RUNDLL32 work without Java, open a command window and type the fully qualified name of your Word doc as a command. It ought to open right up. Try that with different extensions or a URL like "http://www.javaranch.com"
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also look at Java Desktop Integration Components. I've never tried it, but it appears to have functionality for opening files with the registered application. Great if you don't know if the user has Word or OpenOffice.

JDIC
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow

thank you all for all your replies. mmm, the first solution:
Runtime.getRuntime().exec("C:\program files\OfficeXP\Office10\WINWORD.EXE mydoc.doc") ;

works greate but I need to know the location of the winword.

let me try the dll and the JDIC and tell you my toughts.

thanks
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder how will the command should look like it the file is in a different folder say (rent/mydoc.doc)

Runtime.getRuntime().exec("C:\program files\OfficeXP\Office10\WINWORD.EXE mydoc.doc") ;
 
Darrell Morello
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You just have to write the path. Thats all.

Do you mean something like this?


[ May 28, 2005: Message edited by: Darrell Morello ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!