desk
来源:互联网 发布:日本转运公司 知乎 编辑:程序博客网 时间:2024/05/22 03:32
Jdk1.6以后新增加了一个类--DeskTop,在JDK中它的解释是这样的:
The Desktop
class allows a Java application to launch associated applications registered on the native desktop to handle a URI
or a file.
Supported operations include:
- launching the user-default browser to show a specified URI;
- launching the user-default mail client with an optional
mailto
URI; - launching a registered application to open, edit or print a specified file.
这段话的意思是:
DeskTop类允许一个Java应用程序启动本地的另一个应用程序去处理URI或文件请求,这个类中包含了如下的几个方法:
1.启动用户默认的浏览器显示指定的URI链接
2.启动用户默认的邮件客户端发送URI指定的邮件
3.启动一个注册应用程序(本地安装了的应用程序)去打开,编辑或打印一个指定的文件
下面,给出一段测试代码说明这个类的功能和使用方法,代码中附有注释:
package com.brucezhang.desktop; import java.awt.Desktop; import java.io.File; import java.net.URI; public class DeskTopTest { private static Desktop desktop; //使用默认的浏览器打开网页 public static void browse(){ if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); try { //URI指定网页的地址 desktop.browse(new URI("http://blog.csdn.net/dlutbrucezhang?viewmode=contents")); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } } //编辑文件 public static void edit(){ if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); try { desktop.edit(new File("D:\\BruceZhang.txt")); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } } //打开文件,它和编辑文件的过程类似,都是能看到文件的显示 public static void open() { if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); try { desktop.open(new File("D:\\BruceZhang.txt")); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } } //打印指定的文件 public static void print() { if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); try { desktop.print(new File("D:\\BruceZhang.txt")); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub browse(); edit(); open(); print(); } }
原来的网址:http://www.open-open.com/lib/view/open1375523315890.html
0 0
- desk
- Service Desk
- Trading Desk
- Desk Top
- Open Source Help Desk List
- android Desk桌面一键锁屏 源码
- FileMaker 8 Functions and Scripts Desk Reference
- 透明桌面便签(Desk Note)
- Learn Adobe Dreamweaver Videos With Help Desk!
- Parallels Desk中Boot Camp问题解决
- Dynamics CRM Unified Service Desk 技术分享
- 利用SharePoint 2013 定制Service Desk 服务台!
- JIRA Service Desk获得 ITIL 认证
- 利用SharePoint 2013 创建Service Desk 网站之创建Service Desk网站及表单库!
- Rob Pike:OO Isn't Everything(From JDJ News Desk)
- Transact-SQL Desk Reference: For Microsoft SQL Server
- Windows XP All-in-One Desk Reference For Dummies
- Linux All-in-One Desk Reference For Dummies
- R语言绘图篇(二)
- 钩子方法
- Toad 使用快速入门(转贴)
- 电动葫芦运行异常响声如何解决?
- Npoi导出Excel操作类
- desk
- 面向对象部分_206
- web.xml中 Listener的使用
- uva10487
- Apple更新Macbook Air产品线,将于4.30开始销售新Air
- MFC容器类CArray,CList
- 选购电动葫芦应该注以下问题
- java学习笔记
- vmware clone后,修改的地方