Java File Link createSymbolicLink(File pTargetFile, File pLink)

Here you can find the source of createSymbolicLink(File pTargetFile, File pLink)

Description

Wrapper for creating a symbolic link using java.nio

License

Apache License

Parameter

Parameter Description
pTargetFile The file the link will point to.
pLink The link location.

Exception

Parameter Description
IOException if linking fails.

Declaration

public static void createSymbolicLink(File pTargetFile, File pLink) throws IOException 

Method Source Code

//package com.java2s;
/**/*from   ww  w .j a  va2  s . c o m*/
 * Copyright (C) 2014 Karlsruhe Institute of Technology
 *
 *
 * 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 java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
    /**
     * Wrapper for creating a symbolic link using java.nio
     *
     * @param pTargetFile The file the link will point to.
     * @param pLink The link location.
     *
     * @throws IOException if linking fails.
     */
    public static void createSymbolicLink(File pTargetFile, File pLink) throws IOException {
        Path target = Paths.get(pTargetFile.toURI());
        Path link = Paths.get(pLink.toURI());
        Files.createSymbolicLink(link, target);
    }
}

Related

  1. addSymlinkToFileInsideWorkspace()
  2. createRelativeSymlink(File link, File target, boolean relativize)
  3. createSymbolicLink(@Nonnull File symlink, File target)
  4. followLinks(LinkOption... options)
  5. getLinkOptions(boolean followLinks)
  6. isLink(File f)
  7. isSymbolicLink(File file)