Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Windows Symbolic Link with Java (equivalent to MKLINK)

Could anyone please tell me how to make a symbolic link (in the same way MKLINK does) and/or remove a symbolic link with Java. I have found solutions that use Java as a wrapper and use a Windows native program to accomplish this, but I really want a pure Java solution. Thank you in advance!

like image 953
DeathByTensors Avatar asked Oct 07 '13 16:10

DeathByTensors


1 Answers

Since Java 7 you can do this easily using the NIO package.

Path target = Paths.get("target");
Path link = Paths.get("link");
Files.createDirectory(target);
Files.createSymbolicLink(link, target);

Do remember that you do need the correct privileges for this. In my unit test I had to run eclipse as an administrator to make it work (same as that I couldn't create a link from a normal cmd.exe)

like image 158
Thirler Avatar answered Oct 21 '22 08:10

Thirler