Java IO & NIO - Files.isSymbolicLink() Examples
Java IO & NIO - Files.isSymbolicLink() ExamplesJava IO & NIOJavaJava APIPrevious MethodNext MethodClass:java.nio.file.Filesjava.lang.Objectjava.nio.file.FilesLogicBigMethod:public static boo..
·
Class:
java.lang.Objectjava.nio.file.FilesLogicBig
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);
}
}
Output
false
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);
}
}
Output
symbolic link: true
更多推荐
已为社区贡献34条内容
所有评论(0)