Java Is Symbolic Link isSymbolicLink(File file)

Here you can find the source of isSymbolicLink(File file)

Description

is Symbolic Link

License

Apache License

Declaration

public static boolean isSymbolicLink(File file) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.io.IOException;

public class Main {
    public static boolean isSymbolicLink(File file) {
        try {/*from   w ww.ja va  2 s  .  c o m*/
            final File canonicalFile = file.getCanonicalFile();
            final File absoluteFile = file.getAbsoluteFile();
            final File parentFile = file.getParentFile();
            // a symbolic link has a different name between the canonical and absolute path
            return !canonicalFile.getName().equals(absoluteFile.getName()) ||
            // or the canonical parent path is not the same as the file's parent path,
            // provided the file has a parent path
                    parentFile != null && !parentFile.getCanonicalPath().equals(canonicalFile.getParent());
        } catch (IOException e) {
            // error on the side of caution
            return true;
        }
    }
}

Related

  1. isSymbolicLink(File file)
  2. isSymbolicLink(File file)
  3. isSymbolicLink(File file)
  4. isSymbolicLink(File parent, String name)
  5. isSymlink(File base, File curious)