CreateLink method creates a hard link to an existing file - Java File Path IO

Java examples for File Path IO:Symbolic Link

Description

CreateLink method creates a hard link to an existing file

Demo Code

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
  public static void main(String[] args) throws Exception {
    try {//from  w  w  w .j a  v  a  2  s  .co  m
      Path targetFile = Paths.get("C:/home/docs/users.txt");
      Path linkFile = Paths.get("C:/home/music/users.txt");
      Files.createLink(linkFile, targetFile);
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }

}

Related Tutorials