Java File Link createSymbolicLink(@Nonnull File symlink, File target)

Here you can find the source of createSymbolicLink(@Nonnull File symlink, File target)

Description

create Symbolic Link

License

Apache License

Declaration

public static @Nonnull File createSymbolicLink(@Nonnull File symlink, File target) throws IOException 

Method Source Code


//package com.java2s;
/*/*from w  w w.j  av  a 2s  .c o m*/
 * Copyright 2014 The Codehaus Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.annotation.Nonnull;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;

public class Main {
    public static @Nonnull File createSymbolicLink(@Nonnull File symlink, File target) throws IOException {
        Path link = symlink.toPath();
        if (!Files.exists(link, LinkOption.NOFOLLOW_LINKS)) {
            link = java.nio.file.Files.createSymbolicLink(link, target.toPath());
        }
        return link.toFile();

    }
}

Related

  1. addSymlinkToFileInsideWorkspace()
  2. createRelativeSymlink(File link, File target, boolean relativize)
  3. createSymbolicLink(File pTargetFile, File pLink)
  4. followLinks(LinkOption... options)
  5. getLinkOptions(boolean followLinks)
  6. isLink(File f)