Checking a Symbolic Link - Java File Path IO

Java examples for File Path IO:Symbolic Link

Description

Checking a Symbolic Link

Demo Code

import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

public class Main {
  public static void main(String[] args) {

    Path link = FileSystems.getDefault().getPath("test");
    Path target = FileSystems.getDefault().getPath("C:/folder1/photos",
        "test.jpg");
    // check if a path is a symbolic link - solution 1
    boolean link_isSymbolicLink_1 = Files.isSymbolicLink(link);
    boolean target_isSymbolicLink_1 = Files.isSymbolicLink(target);
    System.out.println(link.toString() + " is a symbolic link ? "
        + link_isSymbolicLink_1);/*w ww  .  j  a v  a 2s. c om*/
    System.out.println(target.toString() + " is a symbolic link ? "
        + target_isSymbolicLink_1);
  }
}

Result


Related Tutorials