private static boolean isSymbolicLink ( final File file , File parentFile ) throws PrivilegedActionException { File canonicalParentDir = getCanonicalFile ( parentFile ) ; File fileInCanonicalParentDir = new File ( canonicalParentDir , file . getName ( ) ) ; File canonicalFile = getCanonicalFile ( fileInCanonicalParentDir ) ; return ! canonicalFile . equals ( fileInCanonicalParentDir . getAbsoluteFile ( ) ) ; }
Test if a file is a symbolic link . Test only the file . A symbolic link elsewhere in the path to the file is not detected .