Java Desktop.open(File file)
Syntax
Desktop.open(File file) has the following syntax.
public void open(File file) throws IOException
Example
In the following code shows how to use Desktop.open(File file) method.
/* w w w . j a v a 2 s .c o m*/
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] a) {
try {
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}
desktop.open(new File("c:\\a.txt"));
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
Home »
Java Tutorial »
java.awt »
Java Tutorial »
java.awt »