Java IO & NIO Java Java API
Class:
java.nio.file.Files
Method:
public static boolean isSymbolicLink(Path path)
Tests whether a file is a symbolic link.
- Parameters:
-
path
- The path to the file
- Returns:
-
true
if the file is a symbolic link;
false
if the file does not exist, is not a symbolic link, or it cannot be determined if the file is a symbolic link or
not.
Examples
package com.logicbig.example.files;
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path;
public class IsSymbolicLinkExample {
public static void main(String... args) throws IOException { Path path = Files.createTempFile("test-file", ".txt"); boolean symbolicLink = Files.isSymbolicLink(path); System.out.println(symbolicLink); } }
Outputfalse
package com.logicbig.example.files;
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path;
public class IsSymbolicLinkExample2 {
public static void main(String... args) throws IOException { Path dir = Files.createTempDirectory("test-dir"); Path path = Files.createTempFile(dir, "test-file", ".txt"); //this will fail if not run with admin privileges Path symPath = Files.createSymbolicLink(dir.resolve("sym-" + path.getFileName()), path); boolean symbolicLink = Files.isSymbolicLink(symPath); System.out.println("symbolic link: " + symbolicLink); } }
Outputsymbolic link: true
|
|