For example, I want to open a PPT file, how to do? The simplest way to call system default is to open PowerPoint.
The Java.awt.Desktop class is used here.
DesktopClass allows a Java application to launch an affiliate application that has been registered on the native desktop to process URI or file.
Supported operations include the following:
- Launches the user's default browser to display the specified URI;
- Launches
mailto the user's default mail client with an optional URI;
- Launches the registered application to open, edit, or print the specified file.
Here's a chestnut:
Package Com.sujian;import java.awt.desktop;import java.io.file;import java.io.ioexception;/** * Test open file with default program * * @ Author * @version 1.0, July 9, 2015 */public class Desktoptest { //the path where the file is located public static final String path = "d:/ Test.pptx "; public static void Main (string[] args) { Desktop desktop = Desktop. Getdesktop (); File File = new file (PATH); try { desktop.open (file); } catch (IOException e) { e.printstacktrace ();}} }
Java calls system default program open