JAvaデスクトップアイコンの作成ショートカット

1786 ワード

具体的な実装ソース
	

	/**
	 *         
	 * 
	 * @param fileOrFolderPath
	 *                  
	 * @param writeShortCutPath
	 *                  (     )
	 */
	public static void createShortCut(String fileOrFolderPath,String writeShortCutPath) {
		JShellLink link = new JShellLink();
		writeShortCutPath.replaceAll("/", "\\");
		String folder = writeShortCutPath.substring(0, writeShortCutPath.lastIndexOf("\\"));
		String name = writeShortCutPath.substring(writeShortCutPath.lastIndexOf("\\") + 1, writeShortCutPath.length());
		//System.out.println(fileOrFolderPath);
		link.setName(name);//            
		link.setFolder(folder);//             
		
		 
		link.setPath(fileOrFolderPath); 
		link.save();
	}

	/**
	 *             
	 * 
	 * @param fileFolderPath
	 *                  
	 */
	public static String getShortCutRealPath(String fileFolderPath) {
		//               ,        
		fileFolderPath.replaceAll("/", "\\");
		String folder = fileFolderPath.substring(0, fileFolderPath.lastIndexOf("\\"));
		String name = fileFolderPath.substring(fileFolderPath.lastIndexOf("\\") + 1, fileFolderPath.length());
		JShellLink link = new JShellLink(folder, name);
		link.load();
		//System.out.println(link.getPath());
		return link.getPath();
	}
mainメソッド呼び出し:
// 
	public static void main(String args[]) {
		String fileFolderPath = "C:\\Users\\Administrator\\Desktop\\client\\app\\client.exe";//      
		String writeFolderPath = "C:\\Users\\Administrator\\Desktop\\client.exe"; //    
		createShortCut(fileFolderPath, writeFolderPath);
		//String path=getShortCutRealPath(writeFolderPath);
		//System.out.println(path);
	}

完全なソースコードはここでダウンロードすることができます--クリックしてリンクを開きます