java - 在 Java 中检测符号链接(symbolic link)

标签 java unix filesystems symlink

给定一个 Java 'File' 对象,我如何检测它是否引用了符号链接(symbolic link)?

(如果有帮助/重要,我知道文件指的是目录,而不是文件)

最佳答案

File.getCanonicalPath()解析符号链接(symbolic link)

A canonical pathname is both absolute and unique. The precise definition of canonical form is system-dependent. This method first converts this pathname to absolute form if necessary, as if by invoking the getAbsolutePath() method, and then maps it to its unique form in a system-dependent way. This typically involves removing redundant names such as "." and ".." from the pathname, resolving symbolic links (on UNIX platforms), and converting drive letters to a standard case (on Microsoft Windows platforms).

我假设您可以比较 getCanonicalPath()getAbsolutePath() 的结果。

更新:这个问题似乎已经被问过了 - 检查 the answers there

关于java - 在 Java 中检测符号链接(symbolic link),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2490351/

相关文章:

java - 在java中只调用一次相同的方法

java - 使用 Gradle 监听器有哪些额外好处?比 TestNG 有更多好处吗?

shell - 从文本文件中打印非连续行的快速 Unix 命令?

Java - 获取目录中的最新文件?

java - 在 Eclipse 中查找所有出现的函数

java - 将记录从数据库转储到 CSV 格式的文件

c - 将 Unix 移植到 Windows - pwd.h 的使用

c - 很好的 C 库集合?

.net - 使用 .Net 检查文件系统容量的最佳方法是什么?

c# - .net 框架是否提供使用文件系统的异步方法?