• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Open a file

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I Open a Word or Excel or any other file using java application
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use can use the process class.
eg. Process p = Runtime.getRuntime().exec("<executble file name iec:\word.exe>","<document file name>");
The process class is the best way to invoke a file from word. Like this u can use the same class to call any exe file.
real eg:
Process p = Runtime.getRuntime().exec("c:\word.exe","test.doc");
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried this
Process p = Runtime.getRuntime().exec("E:\Program Files\Microsoft Office\Office\winword.exe","test.doc");
and I get an Illegal escape character
Do you have an idea?
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nisha & rajarajan,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardners!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Younes,
Try
Process p = Runtime.getRuntime().exec("E:\\Program Files\\Microsoft Office\\Office\\winword.exe","test.doc");
It still won't work. Can you figure out why?
[ June 12, 2002: Message edited by: Dirk Schreckmann ]
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If all you want to do is open and read/write a file then you can use the FileReader and FileWriter classes.
 
nisha Sham
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dirk
I tried with
Process p = Runtime.getRuntime().exec("C:\\Program Files\\Microsoft Office\\Office\\winword.exe" ,"C:\\backup\\testt.doc");
When run the application following error prompt as
java.io.IOException: CreateProcess: C:\Program Files\Microsoft Office\Office\winword.exe,C:\backup\testt.doc error=2
at java.lang.Win32Process.create(Native Method)
.....................

showing that there is some error in Win32Process class....
Please help !
Thanks
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I tried doing :
Runtime.getRuntime().exec("C:\\Program Files\\Microsoft Office\\Office\\winword.exe C:\\hello.doc");
and it works. The hello.doc has to be there already existing.
Can someone throw some light on :
(a) How to use the .exec(String, String[]) version. ( name, value pair thing mentioned in javadoc is confusing )
(b) How to create a new document ( ie when hello.doc is not existing )
 
nisha Sham
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mohan

I Succeeded . Thanks Mohan
 
We don't have time for this. We've gotta save the moon! Or check this out:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic