用Java创建快捷方式链接(.lnk)

3

我正在用Java编写安装程序(启动器),需要在过程中能够在用户桌面上创建快捷方式。

我对任何想法都很感兴趣,以找到最佳方法。我考虑的一个选项是在Windows上使用VB脚本并使用本地的“shortcut.exe”来为我完成它,但最好使用第三方文件实用程序。


为什么不直接调用shortcut.exe而不使用VBS呢? - Federico klez Culloca
2个回答

2
  /**
   * 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();
  }

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接