This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Open a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Open a file" Watch "Open a file" New topic
Author

Open a file

nisha Sham
Greenhorn

Joined: Jun 12, 2002
Posts: 19
How can I Open a Word or Excel or any other file using java application
rajarajan
Greenhorn

Joined: Jun 03, 2002
Posts: 2
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

Joined: Jan 13, 2002
Posts: 479
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?


Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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

Joined: May 05, 2000
Posts: 13974
If all you want to do is open and read/write a file then you can use the FileReader and FileWriter classes.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
nisha Sham
Greenhorn

Joined: Jun 12, 2002
Posts: 19
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

Joined: Sep 28, 2001
Posts: 142
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

Joined: Jun 12, 2002
Posts: 19
Mohan

I Succeeded . Thanks Mohan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Open a file
 
Similar Threads
opening RAR file
Eclipse - File -> Open ?
help me the code
How Do I get the CodeKitchen Samples Out of the Jar File?
writing to a file in /WEB-INF/ from a servlet