Creating shortcut links (.lnk) from Java

孤街浪徒 提交于 2019-12-22 11:01:38

问题


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.

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.


回答1:


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

Complete example here : Create an Internet Shortcut (Windows)




回答2:


See this similar question. and this.

After a quick google search I found this java library: http://alumnus.caltech.edu/~jimmc/jshortcut/



来源:https://stackoverflow.com/questions/3426314/creating-shortcut-links-lnk-from-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!