Skip to content Skip to sidebar Skip to footer

Android: Determining A Symbolic Link

I am scanning all directories starting from '/' to find some particular directories like 'MYFOLDER'. However, the folder is that I get double instances of the same folder. This occ

Solution 1:

This is essentially how they do in Apache Commons (subject to their license):

publicstaticbooleanisSymlink(File file)throws IOException {
  File canon;
  if (file.getParent() == null) {
    canon = file;
  } else {
    FilecanonDir= file.getParentFile().getCanonicalFile();
    canon = newFile(canonDir, file.getName());
  }
  return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
}

Edit thanks to @LarsH comment. The above code only checks whether the children file is a symlink.

In order to answer the OP question, it's even easier:

publicstaticbooleancontainsSymlink(File file) {
  return !file.getCanonicalFile().equals(file.getAbsoluteFile());
}

Post a Comment for "Android: Determining A Symbolic Link"