java.awt.Desktop vs Runtime.exec()
Posted by ixmal on May 10, 2006 at 7:19 PM EDT
Desktop API vs Runtime.exec()
I'm often asked why is that new class,
java.awt.Desktop, is introduced. They state all the required actions can be performed with the call to one of Runtime.exec() methods:
Desktop.getDesktop().open(new File(filename));
is close to
Runtime.getRuntime().exec("start " + filename);
So I decided to write a couple of words about this issue to answer the most of such questions at once:)The difference is...
The problem with the "start" invocation is that it only works on the Windows platform. It will fail on the Mac, Linux, and Solaris platforms. With the Desktop API, you can be guaranteed that it will start an application on all platforms.
There are also lots of other handy features in the new API, such as open, edit, print, and two special actions - browse and mail - that launch separate processes.
See
java.awt.Desktop JavaDoc for details.Related Topics >>
Blog Links >>
- Login or register to post comments
- Printer-friendly version
- ixmal's blog
- 4516 reads





