Java.Streams.What is a “symbolic link”?

A symbolic link is a special file that points to another file or directory. Think of it like a shortcut or alias.

  • It doesn’t hold the actual data
  • It just contains a reference (a path) to the real file or folder

📌 Example

Let’s say you have:

/home/stanley/documents/report.txt

You create a symbolic link:

/home/stanley/report_link.txt → points to → /home/stanley/documents/report.txt

Now, if you open or read from report_link.txt, it behaves just like the original file.

✅ Key Characteristics

FeatureDescription
TypeA special file that links to another
Can link toFiles or directories
Works acrossFile systems (unlike hard links)
Can breakIf the target file is deleted or moved
In Java?Supported via java.nio.file.Path + Files.createSymbolicLink()

🔁 Symbolic Link vs Hard Link

FeatureSymbolic LinkHard Link
Points toPath (name)Inode (actual data)
Cross-partition?✅ Yes❌ No
Detectable?✅ Yes (isSymbolicLink)❌ Appears like original
Breaks if target removed?✅ Yes❌ No (file stays)

🧪 Symbolic Links in Java (NIO)

import java.nio.file.*;

public class SymlinkDemo {
    public static void main(String[] args) throws Exception {
        Path target = Paths.get("real_file.txt");
        Path link = Paths.get("shortcut.txt");

        Files.createSymbolicLink(link, target);

        System.out.println("Symlink created: " + link + " → " + target);
    }
}

Check if a file is a symlink:

Files.isSymbolicLink(Paths.get("shortcut.txt"));

🧵 TL;DR

ConceptSymbolic Link
What is it?A file that points to another file/directory
Also calledsymlink, soft link
Breaks if target deleted?✅ Yes
Cross-filesystem support?✅ Yes
Java support?✅ Since Java 7 (java.nio.file)
This entry was posted in Без рубрики. Bookmark the permalink.

Leave a Reply

Your email address will not be published.