Close

Java IO & NIO - Files.readSymbolicLink() Examples

Java IO & NIO Java Java API 


Class:

java.nio.file.Files

java.lang.Objectjava.lang.Objectjava.nio.file.Filesjava.nio.file.FilesLogicBig

Method:

public static Path readSymbolicLink(Path link)
                             throws IOException

Reads the target of a symbolic link.

Parameters:
link - the path to the symbolic link
Returns:
a Path object representing the target of the link


Examples


package com.logicbig.example.files;

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

public class ReadSymbolicLinkExample {

public static void main(String... args) throws IOException {
Path dirPath = Files.createTempDirectory("test-dir");
Path filePath = Files.createTempFile(dirPath, "test-file", ".txt");
System.out.println("Source path: " + filePath);
//must run as admin
Path symPath = Files.createSymbolicLink(dirPath.resolve("sym-test-file.txt"), filePath);
System.out.println("Symbolic link path: " + symPath);
Path path = Files.readSymbolicLink(symPath);
System.out.println("readSymbolicLink: " + path);
}
}

Output

Source path: C:\Users\Joe\AppData\Local\Temp\test-dir3055775170961546378\test-file4634677381413044378.txt
Symbolic link path: C:\Users\Joe\AppData\Local\Temp\test-dir3055775170961546378\sym-test-file.txt
readSymbolicLink: C:\Users\Joe\AppData\Local\Temp\test-dir3055775170961546378\test-file4634677381413044378.txt




See Also