我正在用 Java 编写安装程序(启动程序),并且需要能够在此过程中在用户桌面上创建快捷方式。
我对任何想法都感兴趣,认为这是最好的方法。我考虑过的一个选择是在 Windows 上使用 VB 脚本并使用本机“shortcut.exe”为我完成它,但是首选第三方文件实用程序。
/**
* Create an Internet shortcut
* @param name name of the shortcut
* @param where location of the shortcut
* @param target URL
* @param icon URL (ex. http://www.server.com/favicon.ico)
* @throws IOException
*/
public static void createInternetShortcut
(String name, String where, String target, String icon)
throws IOException
{
FileWriter fw = new FileWriter(where);
fw.write("[InternetShortcut]\n");
fw.write("URL=" + target + "\n");
if (!icon.equals("")) {
fw.write("IconFile=" + icon + "\n");
}
fw.flush();
fw.close();
}
See this similar question. and this.
快速谷歌搜索后,我找到了这个 java 库:http://alumnus.caltech.edu/~jimmc/jshortcut/