Java Is Symbolic Link isSymlink(File file)

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

Description

is Symlink

License

Apache License

Declaration

public static boolean isSymlink(File file) throws IOException 

Method Source Code

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

import java.io.File;

import java.io.IOException;

public class Main {
    private static final char SYSTEM_SEPARATOR = File.separatorChar;

    public static boolean isSymlink(File file) throws IOException {
        if (file == null) {
            throw new NullPointerException("File must not be null");
        }/*from w w w  .  j a  va2  s.  com*/
        if (isSystemWindows()) {
            return false;
        }
        File fileInCanonicalDir = null;
        if (file.getParent() == null) {
            fileInCanonicalDir = file;
        } else {
            File canonicalDir = file.getParentFile().getCanonicalFile();
            fileInCanonicalDir = new File(canonicalDir, file.getName());
        }
        if (fileInCanonicalDir.getCanonicalFile().equals(
                fileInCanonicalDir.getAbsoluteFile())) {
            return false;
        }
        return true;
    }

    static boolean isSystemWindows() {
        return SYSTEM_SEPARATOR == '\\';
    }
}

Related

  1. isSymbolicLink(File file)
  2. isSymbolicLink(File parent, String name)
  3. isSymlink(File base, File curious)
  4. isSymLink(File file)
  5. isSymlink(File file)
  6. isSymlink(File file)
  7. isSymlink(File file)
  8. isSymlink(File file)
  9. isSymlink(File file)