package test;
import java.awt.Desktop;
import java.io.File;
import java.net.URI;
public class DeskTopTest {
private static Desktop desktop;
public static void main(String[] args) {
// browse();
edit();
open();
// print();
}
// 使用默认的浏览器打开网页
public static void browse() {
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
try {
desktop.browse(new URI("www.baidu.com"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
// 使用设置的默认编辑器打开文件
public static void edit() {
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
try {
desktop.edit(new File("D:\\DesktopTest.txt"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
// 使用系统默认的编辑器打开文件
public static void open() {
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
try {
desktop.open(new File("D:\\DesktopTest.txt"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
// 使用配置的默认打印机打印文件
public static void print() {
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
try {
desktop.print(new File("D:\\DesktopTest.txt"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)