从Java创建快捷方式链接(.lnk) [英] Creating shortcut links (.lnk) from Java

查看:1088
本文介绍了从Java创建快捷方式链接(.lnk)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am writing an installer (launcher) in Java and require the ability to be able to create a shortcut on the users desktop during the process.

我对任何想法感兴趣是最好的方法。我考虑的一个选项是在Windows上使用VB脚本并使用本机'shortcut.exe'为我做,但是第三方文件实用程序将是首选。

I am interested in any ideas as the best way to do this. My one option I have considered is using a VB Script on windows and using the native 'shortcut.exe' to do it for me, however a third party file utility would be preferred.

推荐答案

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

此处的完整示例:创建Internet快捷方式(Windows)

这篇关于从Java创建快捷方式链接(.lnk)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆