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