JAVA创建快捷方式

来源:互联网 发布:csv导入mysql 编辑:程序博客网 时间:2024/05/16 14:04
package shortcust;import net.jimmc.jshortcut.JShellLink;public class CreateShortcust {/** * @param args */public static void main(String[] args) {String fileFolderPath="E:\\test\\test.html";String writeFolderPath="E:\\Gongqi";createShortCut(fileFolderPath, writeFolderPath, null);String path=getShortCutRealPath(writeFolderPath);System.out.println(path);String targetPath="D:\\Test1";createShortCut(targetPath+"\\Tomcat\\bin\\startup.bat", targetPath+"\\ShortCut\\startup.bat", null);}/** * 创建快捷方式 * @param fileorFolderPath源文件夹路径 * @param writeShortCutPath目标文件路径(快捷方式型) */public static void createShortCut(String fileorFolderPath, String writeShortCutPath, String arguments){JShellLink link=new JShellLink();writeShortCutPath=writeShortCutPath.replaceAll("/", "\\");String folder=writeShortCutPath.substring(0, writeShortCutPath.lastIndexOf("\\")+1);String name=writeShortCutPath.substring(writeShortCutPath.lastIndexOf("\\")+1, writeShortCutPath.length());link.setName(name);//目标快捷方式文件夹名称link.setFolder(folder);//目的快捷方式文件路径片段link.setPath(fileorFolderPath);if(arguments != null && !"".equals(arguments.trim())){link.setArguments(arguments);}link.save();}public static String getShortCutRealPath(String fileFolderPath){fileFolderPath=fileFolderPath.replaceAll("/", "\\");String folder=fileFolderPath.substring(0, fileFolderPath.lastIndexOf("\\"));String name=fileFolderPath.substring(fileFolderPath.lastIndexOf("\\"), fileFolderPath.length());JShellLink link=new JShellLink(folder, name);link.load();return link.getPath();}}

需要jshortcut.jar和jshortcut.dll,当在eclipse里面运行的时候jshortcut.dll放在src根目录下面即口,当需要打包为jar的是时候jshortcut.dll应该放在跟jar同级目录下面

所需资源http://download.csdn.net/detail/zyf814/5706155

原创粉丝点击