首页javafile_attributeJava I/O - 如何检查存在而不遵循符号链接

Java I/O - 如何检查存在而不遵循符号链接

我们想知道如何检查存在而不遵循符号链接。
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
  public static void main(String[] args) throws Exception {
    Path firstPath = Paths.get("/home/music/users.txt");
    Path secondPath = Paths.get("/docs/status.txt");
    System.out.println("exists (Do not follow links): " + Files.exists(firstPath, LinkOption.NOFOLLOW_LINKS));
    
  }
}