Far*_*an 8 directory symlink android
我正在扫描从"/"开始的所有目录,以找到一些特定的目录,如"MYFOLDER".但是,该文件夹是我获得同一文件夹的双重实例.发生这种情况是因为一个文件夹位于"/ mnt/sdcard/MYFOLDER"中,并且同一文件夹中的符号链接位于"/ sdcard/MYFOLDER"中.
我的问题是,"有没有办法确定文件夹是否是符号链接?".请给我一些建议..
rds*_*rds 14
这基本上是他们在Apache Commons中的行为(取决于他们的许可):
public static boolean isSymlink(File file) throws IOException {
File canon;
if (file.getParent() == null) {
canon = file;
} else {
File canonDir = file.getParentFile().getCanonicalFile();
canon = new File(canonDir, file.getName());
}
return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
}
Run Code Online (Sandbox Code Playgroud)
编辑感谢@LarsH评论.以上代码仅检查子文件是否为符号链接.
为了回答OP问题,它更容易:
public static boolean containsSymlink(File file) {
return !file.getCanonicalFile().equals(file.getAbsoluteFile());
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4916 次 |
最近记录: |