给定一个 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/