Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a .lnk file on the desktop using Java?

Tags:

java

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.

like image 587
pa pa Avatar asked Jan 22 '26 21:01

pa pa


1 Answers

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);
like image 99
aliaslion Avatar answered Jan 24 '26 10:01

aliaslion