import java.net.URI;
import java.awt.Desktop;
public class OpenURI {
public static void main(String [] args) {
if( !java.awt.Desktop.isDesktopSupported() ) {
System.err.println( "Desktop is not supported (fatal)" );
System.exit( 1 );
}
if ( args.length == 0 ) {
System.out.println( "Usage: OpenURI [URI [URI ... ]]" );
System.exit( 0 );
}
java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
if( !desktop.isSupported( java.awt.Desktop.Action.BROWSE ) ) {
System.err.println( "Desktop doesn't support the browse action (fatal)" );
System.exit( 1 );
}
for ( String arg : args ) {
try {
java.net.URI uri = new java.net.URI( arg );
desktop.browse( uri );
}
catch ( Exception e ) {
System.err.println( e.getMessage() );
}
}
}
}
OpenURI
最新推荐文章于 2025-12-02 14:29:41 发布
本文提供了一个使用Java实现打开单个或多个URI链接的例子。该程序首先检查当前桌面环境是否支持所需的操作,并验证是否支持浏览功能。接着,程序接收命令行参数作为URI链接,并逐一尝试打开。
5603

被折叠的 条评论
为什么被折叠?



