Java Is Same File isSame(File file1, File file2)

Here you can find the source of isSame(File file1, File file2)

Description

Returns true if the canonical files passed as arguments have the same canonical file.

License

Apache License

Declaration

public static boolean isSame(File file1, File file2) 

Method Source Code

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

import java.io.File;

import java.io.IOException;

public class Main {
    /**/*from   ww w. j  av  a 2s  . co  m*/
     * Returns <code>true</code> if the canonical files passed as arguments have
     * the same canonical file.
     */
    public static boolean isSame(File file1, File file2) {
        return canonicalFile(file1).equals(canonicalFile(file2));
    }

    /**
     * A 'checked exception free' version of {@link File#getCanonicalFile()}.
     */
    public static File canonicalFile(File file) {
        try {
            return file.getCanonicalFile();
        } catch (final IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. isSame(File file1, File file2)
  2. isSame(File fileA, File fileB)