Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to open a specific file when invoking an application?

Status
Not open for further replies.

beck4525

Programmer
Dec 26, 2001
2
US
When invoking an application using the Runtime exec() method, is it possible to also open a specific file in the application? For example, if you are wanting the user to be able to view a file in Word, I know how to invoke word, but not with the appropriate file open for the user to see.
Many thanks in advance for any help.
 
How many people will be using this app? Meaning, if you hardcode a path for a document, there is not gurantee that the document will reside in the same folder, on the same drive letter, etc. IF that is not a problem, something like

Runtime.getRuntime().exec("C:\\Program
Files\\MSOffice\\Winword\\WINWORD.EXE d:\\usr\\ray\\java\\q7\\documentname.doc");


might work
 
Thanks very much donniea21. Your suggestion works when I type in the path as suggested...

Runtime.getRuntime().exec("C:\\Program Files/Microsoft Office/Office/Winword.exe test.doc");

If the file name (test.doc) was stored in a String variable, how would I include that instead of hard-typing "test.doc"???
Many thanks again
beck4525
 
Im not really sure but you may be able to store the string for the application in a string and the doc name in another and then concat them

String wordApp = "C:\\Program Files/Microsoft Office/Office/Winword.exe";

String docName = "test.doc";

Runtime.getRuntime().exec(wordApp + " " + docName);

 
Realized that you don't really need to use 2 variables.

String docName = "test.doc";

java.lang.Runtime.getRuntime().exec("C:\\Program Files/Microsoft Office/Office/Winword.exe " + docName);

note the space after .exe

this should work for ya.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top