Search code examples
javasymlinkocpjp

OCPJP 8 What is a Symbolic link using NIO2


I am trying to get Java 8 certification i already have Java 6 a long time ago and Java 7 is my weak point because i havent work with it i am a little confuse.

What is a symbolic Link??

According to wikipedia.

In computing, a symbolic link (also symlink or soft link) is a term for any file that contains a reference to another file or directory in the form of an absolute or relative path and that affects pathname resolution.

My questions are.

How Java recognize a symbolic link i mean when this would print true?

final Path path = ...
System.out.println(Files.isSymbolicLink(path));

Perhaps this is a silly question but i really want to know!!


Solution

  • On my ubuntu, I have create two files in /tmp/

    echo "Hello world" > file.txt
    ln -s file.txt link.txt
    

    If I check for both file .

    Files.isSymbolicLink(Paths.get("/tmp/file.txt")) //false
    Files.isSymbolicLink(Paths.get("/tmp/link.txt")) //true
    

    Same would works on Windows with a file and a link made with mklink.