Java Is Symbolic Link isSymlink(File file)

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

Description

Checks if the given file represents a symlink.

License

Open Source License

Declaration

public static boolean isSymlink(File file) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *
 * Copyright (c) 2004-2011 Oracle Corporation.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: /* w  w w .ja  v a2 s.  com*/
 *
 *    Kohsuke Kawaguchi, Winston Prakash
 *     
 *
 *******************************************************************************/

import java.io.File;

import java.io.IOException;

public class Main {
    /**
     * Checks if the given file represents a symlink.
     */
    public static boolean isSymlink(File file) throws IOException {
        String name = file.getName();
        if (name.equals(".") || name.equals("..")) {
            return false;
        }

        File fileInCanonicalParent;
        File parentDir = file.getParentFile();
        if (parentDir == null) {
            fileInCanonicalParent = file;
        } else {
            fileInCanonicalParent = new File(parentDir.getCanonicalPath(), name);
        }
        return !fileInCanonicalParent.getCanonicalFile().equals(fileInCanonicalParent.getAbsoluteFile());
    }
}

Related

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