How can I create a .lnk file using Java? such as I want to create a .lnk file on my desktop which opens the following directory C:\Windows\System32\calc.exe. I have found this website but it is for creating an URL for the website shortcut. it basically write out 2 lines ([InternetShortcut] and
URL = XXXXXX.com) by using FileWriter and save it as .URL file. but it seems not working with lnk extension.
You can use a *.symlink file. It works too, and it is simple to create.
Here is a short Java snippet to create a *.symlink file:
// Link target
Path targetPath = Path.of("C:/Windows/System32/calc.exe");
// Link destination
// You can replace Calculator with your own file name (without extension).
Path linkPath = Path.of(System.getProperty("user.home") + "/Desktop/Calculator");
Files.createSymbolicLink(linkPath, targetPath);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With