Java directly open file or Hyperlink __java

Source: Internet
Author: User

Java Open file or hyperlink directly

Summarize how to execute system external commands in Java open specific hyperlinks

Wangyancheng (wangyancheng#ushayden.com), author/editor, Ushayden, Inc.

The December 13, 2010 article summarizes the processing methods for opening a specified file or link using operating system commands in a Java environment directory scenarios different operating system commands based on JDK1.6 java.awt.Desktop one, application scenarios

Automatically opens the specified link or file when the application logic processing is complete. two, different operating system commands

OS Action Category Command Description
Window Open link rundll32 Url.dll,fileprotocolhandler http://www.163.com
Open File rundll32 Shell32.dll Shellexec_rundll C:/boot.ini
Unix Open link

1. Define a collection of link processing commands.

2, verify that the command is available.

3, execution, the link as a parameter to pass.

Open File

1. Define a collection of file processing commands

2, command verification = = "Implementation

Mac Open link

1. Try loading Com.apple.eio.FileManager

2, call Api#openurl (..)

Note: The pass parameter type is a URL

Open File

1. Try loading Com.apple.eio.FileManager

2, call Api#openurl (..)

Note: The pass parameter type is File.geturi (). Tourl (). ToString ()

JDK1.6
Java.awt.Desktop
Open link

1. Try loading Java.awt.Desktop

2, using javareflection mechanism to obtain examples

3, using the javareflection mechanism to call the Browse method

Note: The pass parameter type is a URI

Open File

1. Try loading Java.awt.Desktop

2, using javareflection mechanism to obtain examples

3. Call open method with javareflection mechanism

Note: Pass parameter type file



Back to the top of the page

Iii. relevant information

1, Http://www.davidc.net/programming/java/browsing-urls-and-opening-files

2, http://download.oracle.com/javase/6/docs/api/java/awt/Desktop.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.