0

I want to execute WordPad using the code below.
It runs fine on my pc. But failed to run on other pcs.

String program = "C:\\Program Files\\Windows NT\\Accessories\\wordpad";
String file = "srcFiles\\Resources\\readme.rtf"; //This is the path to the file i want to open with wordpad.
Runtime  load = Runtime.getRuntime();;
try{
 load.exec(program + " " + file);
 }catch(java.io.IOException ioe){
 System.out.println(ioe.getMessage());
 }

Please what am i getting wrong?

Edited by Neon Tetras

3
Contributors
2
Replies
16
Views
3 Years
Discussion Span
Last Post by djslavens
1

Uhm, don't use Runtime OR ProcessBuilder for this, for one, see the API docs for Desktop.open. Then, also, make sure the file is really where you THINK it is AND that your program is running with the "currentWorkingDirectory" that you THINK it is.

Votes + Comments
Thanks. I read the API doc. Fixed my problem
0

If you are going to use Runtime, the you probably need to use a different Runtime.exec. There is one that passes in the program name and command line args as a String array.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.