1.桌面操作类Desktop相关接口如下:
// 判断是否能获取到桌面
static boolean isDesktopSupported();
// 获取Desktop实例
static Desktop getDesktop();
// 启动默认浏览器并打开URI对象
void browse(URI uri);
// 打开文件或文件夹
void open(File file);
// 编辑文件
void edit(File file);
// 打印文件
void print(File file);
// 打开默认邮件客户端
void mail();
// 打开默认邮件客户端,填充由 mailto:URI 指定的消息字段
void mail(URI mailtoURI);
/*
* 判断是否支持action行动, 参数为以下值之一:
* Desktop.Action.OPEN: 打开文件
* Desktop.Action.EDIT: 编辑文件
* Desktop.Action.PRINT: 打印文件
* Desktop.Action.MAIL: 打开邮件
* Desktop.Action.BROWSE: 打开浏览器
*/
boolean isSupported(Desktop.Action action);
2.Demo(打开浏览器并访问我的博客)
public static void main(String[] args) throws IOException {
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
desktop.browse(URI.create("http://www.sunbingbing.cn"));
} else {
System.out.println("无法获取到Desktop实例");
}
}
3.应用
1.访问磁盘并写入一个乱码html
2.while循环执行打开浏览器并访问该html的操作
3.执行程序。。。
4.如果程序执行顺利的话,可能需要重启电脑(没敢试)