• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Open a file

 
nisha Sham
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I Open a Word or Excel or any other file using java application
 
rajarajan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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");
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • 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?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Mohan Panigrahi
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Mohan

I Succeeded . Thanks Mohan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic