• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

open a word document from my application

 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the Runtime class.

e.g
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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") ;
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Your mother was a hamster and your father was a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic