java.awt.Desktop 简介

本文详细介绍了Java中的Desktop类,该类允许应用程序使用系统中注册的关联应用程序来处理特定的文件或URI。支持的操作包括使用默认浏览器打开URI、使用默认邮件客户端处理mailto URI以及使用注册的应用程序打开、编辑或打印文件。

摘自api

The Desktop class allows a Java application to launch associated applications registered on the native desktop to handle a URI or a file.

//使用系统中的关联应用程序来打开特定的文件(或者URI)

Supported operations include://支持的操作包括

  • launching the user-default browser to show a specified URI; //使用默认浏览器打开URI
  • launching the user-default mail client with an optional mailto URI;//使用默认邮件客户端打开任意的mailto地址(optional:任意的)
  • launching a registered application to open, edit or print a specified file.//使用关联的应用程序来打开、编辑或打印文件

This class provides methods corresponding to these operations. The methods look for the associated application registered on the current platform, and launch it to handle a URI or file. If there is no associated application or the associated application fails to be launched, an exception is thrown.

//假如没有关联的应用程序或者不能打开关联应用程序,会抛出exception

An application is registered to a URI or file type; for example, the "sxi" file extension is typically registered to StarOffice. The mechanism of registering, accessing, and launching the associated application is platform-dependent.//关联应用程序会根据平台不同而不同

Each operation is an action type represented by the Desktop.Action class.

Note: when some action is invoked and the associated application is executed, it will be executed on the same system as the one on which the Java application was launched. //调用的应用程序会运行在在java应该程序所运行的系统之上


ps:URL是一种具体的URI

**Start Failed** Internal error java.awt.HeadlessException: No X11 DISPLAY variable was set, or no headful library support was found, but this program performed an operation which requires it, at java.desktop/java.awt.dnd.DragSource.getDefaultDragSource(DragSource.java:226) at com.intellij.platform.ide.bootstrap.UiKt$scheduleUpdateFrameClassAndWindowIconAndPreloadSystemFonts$1$3.invokeSuspend(ui.kt:267) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100) at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:781) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:728) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722) at java.base/java.security.AccessController.doPrivileged(AccessController.java:400) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:750) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
09-22
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值