Here you can find the source of createRelativeSymlink(File link, File target, boolean relativize)
public static File createRelativeSymlink(File link, File target, boolean relativize) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.nio.file.Files; public class Main { public static File createRelativeSymlink(File link, File target, boolean relativize) throws IOException { if (relativize) { // make sure we're working with the full path link = link.getCanonicalFile(); target = target.getCanonicalFile(); try { target = link.getParentFile().toPath().relativize(target.toPath()).toFile(); } catch (Throwable e) { // unable to relativize link target }/*from w ww . j a va 2s. c om*/ } // create symlink via NIO.2 return Files.createSymbolicLink(link.toPath(), target.toPath()).toFile(); } }