以系统默认方式打开某文件
public static void desktopTest() throws IOException {
if (!Desktop.isDesktopSupported()) {
System.out.println("Desktop not supported.");
return;
}
Desktop desktop = Desktop.getDesktop();
File file = new File("D:\\test");
if (file.exists()) {
desktop.open(file);
System.out.println("Done");
} else {
System.out.println("File not exist.");
}
}
Desktop的操作还有browse,edit等,详情见API文档