O'Reilly logo

Java Garage by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Executing an External Application in Java

There are many times that you might like to launch an application that is running on the user's machine. For example, an external Web browser could be used to display help pages. There is a way to do this that is as easy as running it yourself from the command line. All you have to know is its name on the system. To make your Java application open Windows Explorer, write

try {
Runtime.getRuntime().exec("explorer");
} catch(IOException ioe){
System.out.println(ioe.getMessage());
}

You have to catch or rethrow the IOException that this call can occasion. Note that we just pass in the system name, not including the file extension.

Passing Arguments to an External Application

Not only can we start an external ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required