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();
}
}
}
}
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();
}
}
}
}