Java File Link createRelativeSymlink(File link, File target, boolean relativize)

Here you can find the source of createRelativeSymlink(File link, File target, boolean relativize)

Description

create Relative Symlink

License

Open Source License

Declaration

public static File createRelativeSymlink(File link, File target, boolean relativize) throws IOException 

Method Source Code

//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();
    }
}

Related

  1. addSymlinkToFileInsideWorkspace()
  2. createSymbolicLink(@Nonnull File symlink, File target)
  3. createSymbolicLink(File pTargetFile, File pLink)
  4. followLinks(LinkOption... options)
  5. getLinkOptions(boolean followLinks)