Java Create Shortcut

Source: Internet
Author: User

  1. Package com.ts.util.ex.project;
  2. Import Net.jimmc.jshortcut.JShellLink;
  3. /**
  4. * Shortcut Tool Class
  5. *
  6. * @author Ice (qq:494174519,13728989948 (Your code improvement is a common encouragement to us))
  7. *
  8. */
  9. Public class ShortCut {
  10. //need to download Jshortcut.jar directly in Baidu search
  11. public static void Main (String args[]) {
  12. String Filefolderpath = "D:\\test\\jshortcut-0_4.jar";
  13. String Writefolderpath = "D:\\new";
  14. CreateShortcut (Filefolderpath, Writefolderpath);
  15. String Path=getshortcutrealpath (Writefolderpath);
  16. SYSTEM.OUT.PRINTLN (path);
  17. }
  18. /** 
  19. * Create a shortcut
  20. *
  21. * @param Fileorfolderpath
  22. * Source Folder path
  23. * @param Writeshortcutpath
  24. * Destination file path (shortcut type)
  25. */
  26. public static void CreateShortcut (String fileorfolderpath,string writeshortcutpath) {
  27. Jshelllink link = new Jshelllink ();
  28. Writeshortcutpath.replaceall ("/", "\ \");
  29. String folder = writeshortcutpath.substring (0, writeshortcutpath.lastindexof ("\ \"));
  30. String name = writeshortcutpath.substring (Writeshortcutpath.lastindexof ("\ \") + 1, writeshortcutpath.length (  ));
  31. Link.setname (name); //Destination shortcut folder name
  32. Link.setfolder (folder); //Destination shortcut file path fragment
  33. Link.setpath (Fileorfolderpath);
  34. Link.save ();
  35. }
  36. /** 
  37. * Get a shortcut real address
  38. *
  39. * @param Filefolderpath
  40. * Source Folder path
  41. */
  42. public static string Getshortcutrealpath (String filefolderpath) {
  43. //Get the source folder address based on the path and folder name of the shortcut
  44. Filefolderpath.replaceall ("/", "\ \");
  45. String folder = filefolderpath.substring (0, filefolderpath.lastindexof ("\ \"));
  46. String name = filefolderpath.substring (Filefolderpath.lastindexof ("\ \") + 1, filefolderpath.length ());
  47. Jshelllink link = new Jshelllink (folder, name);
  48. Link.load ();
  49. return Link.getpath ();
  50. }
  51. }

Java Create Shortcut

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.