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?

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.

commented: 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.