具体实现源码
/**
* 创建一个快捷方式
*
* @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);
}
完整的源码可以在这里下载-- 点击打开链接