Java Path Relative getRelativeFilename(File base, File target)

Here you can find the source of getRelativeFilename(File base, File target)

Description

Simplistic version: return the substring after the base

License

LGPL

Declaration

public static String getRelativeFilename(File base, File target) 

Method Source Code

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

import java.io.File;

public class Main {
    /**/*from  ww w  .  ja  va 2  s.  c o m*/
     * Simplistic version: return the substring after the base
     */
    public static String getRelativeFilename(File base, File target) {
        return getRelativeFilename(base.getAbsolutePath(), target.getAbsolutePath());
    }

    public static String getRelativeFilename(String sBase, String sTarget) {
        if (sTarget.startsWith(sBase)) {
            if (sBase.endsWith("/") || sBase.endsWith("\\") || sTarget.length() == sBase.length())
                return sTarget.substring(sBase.length());
            else
                return sTarget.substring(sBase.length() + 1);
        } else
            return sTarget; // Leave absolute
    }
}

Related

  1. getRelativeFile(File targetFile, File baseFile)
  2. getRelativeFile(java.io.File srcFile, int upCount, String... childPaths)
  3. getRelativeFile(String baseDir, String fileName)
  4. getRelativeFileFromReference(String ref, File metadataFile)
  5. getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize)
  6. getRelativeFileName(File file, File basedir)
  7. getRelativeFileName(File target, File realativeTo)
  8. getRelativeFileName(String filePath, String directoryPath)
  9. getRelativeFilePath(File absolutePath, File reference)