【问题标题】:Creating shortcut links (.lnk) from Java从 Java 创建快捷链接 (.lnk)
【发布时间】:2011-03-26 11:23:29
【问题描述】:

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

我对任何想法都感兴趣,因为这是最好的方法。我考虑过的一个选择是在 Windows 上使用 VB 脚本并使用本机的“shortcut.exe”为我执行此操作,但是最好使用第三方文件实用程序。

【问题讨论】:

  • 为什么不直接调用shortcut.exe而不使用VBS?

标签: java scripting vbscript shortcut


【解决方案1】:

参见this similar question.this

在谷歌快速搜索后,我找到了这个 java 库:http://alumnus.caltech.edu/~jimmc/jshortcut/

【讨论】:

    【解决方案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();
      }
    

    此处的完整示例:Create an Internet Shortcut (Windows)

    【讨论】:

      猜你喜欢
      • 2013-08-04
      • 2017-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-07
      • 2010-09-23
      • 1970-01-01
      相关资源
      最近更新 更多