2010-08-06 90 views
3

我正在用Java編寫安裝程序(啓動程序),並且需要能夠在此過程中在用戶桌面上創建快捷方式。從Java創建快捷鏈接(.lnk)

我對任何想法都很感興趣,因爲這是最好的方法。我曾考慮過的一個選項是在Windows上使用VB腳本,並使用本機的「shortcut.exe」爲我做,但是第三方文件實用程序將是首選。

+0

爲什麼不打電話不使用VBS shortcut.exe? – 2010-08-06 17:48:51

回答

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)