if (file1 == null) return null; if (file2 == null) return null;
    static File getCommonPart(File file1, File file2) {        String file1AbsPath;        String file2AbsPath;        file1AbsPath = file1.getAbsolutePath();        file2AbsPath = file2.getAbsolutePath();        if (file1AbsPath.equals(file2AbsPath)) {            return new File(file1AbsPath);        }        String[] file1Parts = StringUtils.split(file1AbsPath,                File.separatorChar);        String[] file2Parts = StringUtils.split(file2AbsPath,                File.separatorChar);        int parts1Length = file1Parts.length;        int parts2Length = file2Parts.length;        int minLength = (parts1Length < parts2Length) ? parts1Length                : parts2Length;        String part1;        String part2;        StringBuffer commonsPart = new StringBuffer();        for (int i = 0; i < minLength; i++) {            part1 = file1Parts[i];            part2 = file2Parts[i];            if (!part1.equals(part2)) {                break;            }            if (commonsPart.length() == 0) {                commonsPart.append(part1);            } else {                commonsPart.append(File.separatorChar);                commonsPart.append(part1);            }        }        if (commonsPart.length() == 0) {            return null; // the two files have nothing in common (one on disk c:                         // and the other on d: for ex)        }        return new File(commonsPart.toString());    }